May 31, 2013

SAS Log Options

3 good tips on how to handle full logs in SAS.

Posted by kkwaiser at 08:33 AM | Comments (0)

February 21, 2013

Set SAS to display variable names not labels

I don't understand this default setting but it can be changed.

- Click in or on the Explorer pane to highlight the the Explorer window.
- Select Tools->Options->Explorer in the menus.
- Select the Members tab.
- Double click on the TABLE icon.
- Double click on the &Open action.
- Set the Action command to: VIEWTABLE %8b.ā€™%sā€™.DATA COLHEADING=NAMES
- Click on the Set Default button.
- Save changes and close the Explorer Options window

Posted by kkwaiser at 03:27 PM | Comments (0)

January 29, 2013

Debugging in SAS

I'm working through some tutorials and this seems to be an important topic.

putlog _all_; *prints the current pdv (working data row) to the log;

the _ERROR_ variable increments to one if a syntax error occurs. You can use conditional logic to output variable information to the log.

putlog 'WARNING: blah blah'; * will colorcode the output

data customers /debug; *will enter debug mode;

- doesn't work with SAS Enterprise Guide

Step - goes to nex step
Watch or W [variable] - auto-print variable value when it changes
Deletewatch or DW [variable]
Examine or E [variable] - print a variable value
$ examine varible $quote7. - print variable within quotes and up to 7 characters
List or L [_All_ Files Break INFILES Datasets WATCH] - print all items within the specified option
Set [variable] = [value] - change a variable value

List or L

set [dataset] END=last; * when the data step cycles through the last observation of the dataset 'last' will be set to one. Conditionals can be added to do something special upon reaching the last row;

Posted by kkwaiser at 11:54 AM | Comments (0)

January 28, 2013

Variable Lists

numbered range
total = sum(of Qtr1-Qtr4); *will hit Qtr2, Qtr3, etc.;

name range
specify columns in between those specified
total = sum(of Qtr1--fourth);
total = sum(of Qtr1-numeric-fourth); *only 'numeric' (can use 'character' too) between the variables specified;

name prefix
all columns beginning with specified string

total = sum(of Tot:);


Total = sum(of _All_); *Can also use _Numeric_ or _Character_;

Posted by kkwaiser at 04:39 PM | Comments (0)

SAS FAQ #31346987234: The DSD Infile option

Using the DSD option as part of an infile statement will cause sas to ignore "delimiters" that may be found within a quoted text string.

Two consecutive delimiters will lead to a missing value with DSD.

A source.

Posted by kkwaiser at 01:25 PM | Comments (0)

January 25, 2013

Read variables or datasets with names containing spaces

SAS hates spaces - which I am fine with - but sometimes a variable or dataset exists with spaces in it's name. To get around this put the name/variable into quotes followed by an 'n'.

proc contents data=work.'poorly named dataset'n;


Posted by kkwaiser at 02:43 PM | Comments (0)

January 18, 2013

Create random number string in SAS

Adapted code from here

%let NObs = 52;

data test_psid(keep=psid);
call streaminit(123); /* random num generator seed*/
Min = 100000; Max = 999999; /*range of random number*/
do i = 1 to &NObs;
psid = min + floor((1+Max-Min)*rand("Uniform")); /* uniform integer in Min..Max */

Posted by kkwaiser at 10:08 AM | Comments (0)

January 07, 2013

Importing files in SAS

This will import a comma delimited file. Note that input is required and can be used to specify only certain variables that should be part of the dataset.

DATA work.test3;
infile 'J:\blaise_sample_files\mixed_mode\5_sample_set\sample_other.csv' dlm=',';
input var1 var2;

This SAS pdf has more.

There is also a PROC IMPORT statement but I'm not sure when you would use one approach over the other.

			FILE = "J:\blaise_sample_files\mixed_mode\5_sample_set\sample_other.csv"

Posted by kkwaiser at 12:55 PM | Comments (0)

Where statements in the DATA step

Select a subset of data set that contains only NULLS:

data work.testnulls;
set work.test;
where PushStringToMainIw = ' ';

Select subset of data where a given column contains a value. This gets into some regex for SAS

- the percent sign (%) replaces any number of characters
- the underscore (_) replaces one character

data work.testnulls;
set work.test;
where PushStringToMainIw LIKE '10-1xxx-003%' ;

Posted by kkwaiser at 11:44 AM | Comments (0)

January 04, 2013

_n_ variable in SAS

Creating a post on this because the interwebs appear to be a bit crossed.

One source indicates

The automatic variable _n_ represents the observation numbers.

While another indicates

Each time the DATA step loops past the DATA statement, the variable _N_ increments by 1. The value of _N_ represents the number of times the DATA step has iterated.

I suppose these are equivalent statements if the data step iterates for every observation in the data file.

Posted by kkwaiser at 04:09 PM | Comments (0)

Useful shortcut commands in SAS 9.x

In lieu of hotkeys to toggle between SAS windows I am going to try using the Command prompt (with command shortcut set to ctrl+j).

A somewhat complete list of commands from the SAS people.

Commands to open a new Enhanced Editor or to toggle to the current Editor.

WPGM to go back to original enhanced editor window
WEDIT to create a new enhanced editor window


Posted by kkwaiser at 10:11 AM | Comments (0)