0
votes

Piece of code on Unix Server is not working, but works on PC SAS. When executed in UNIX SAS, the output datasets pc_pf_yes_1 and pc_pf_no_1 both have 0 observations, but no error is observed. In PC SAS, the code works fine and populates the datasets as intended.

The below datastep is within a macro.

data pc_pf_yes_1 pc_pf_no_1;
    set pc_&month._2;
    if primary_flag = "Y" then output pc_pf_yes_1;
    else if primary_flag = "N" then output pc_pf_no_1;
run;

primary_flag is a binary variable with values Y and N, stored as a string length 1. &month. is a macro variable that stores a month name for data selection.

Is there a quirk with UNIX SAS within a macro that I don't know about?

1
What do you mean by not working? What are the differences in the log?Longfish
Edited the question, thanks for pointing that out. No error is shown but the rows from the source dataset are not written to the output datasets. I've checked, the data is fine and works perfectly on PC.Lisle
Hm, i can see no error in your posted code which would make trouble under unix. I would suggest to test this statement with a specific known dataset like set pc_jun_2; to be sure it is not a problem of setting the macro variable or not accesable datasets under unix. You use no library when accessing the pc_month_2 dataset, are you sure the work-dataset is existing on unix?kl78

1 Answers

2
votes

Check the data. If the value of primary_flag has leading spaces or is lower case then it will not match either 'Y' or 'N'. Note that trailing spaces do not matter. To see the leading spaces try printing the variable with the $QUOTE. format.

If you read the data from a text file then primary_flag might have a carriage return on the end of it, which is also hard to see in normal print outs. On a PC the carriage return is part of the end of line marker, but Unix just uses line feed as the end of line marker so the carriage return can end up in the data. Use the TERMSTR=CRLF option on the INFILE statement. Or you can use compress(primary_flag,'0d'x) to remove carriage return characters. To see these and other hidden characters you can print the data using $HEX. format. Or use the LINE statement in the data step that reads the text file.