@YasodaJayaweera wrote:
Thank you very much. Left intending the datalines did the trick. I am running the code in SAS OnDemand. Has this always been the case? I was under the impression that SAS statements are independent of indentation.
SAS statements do not care about extra spaces between words in the code. But you appear to be having issues with your lines of DATA, not your CODE.
If you are using SAS OnDemand then you are using SAS/Studio. Which means any TAB characters that have accidentally been inserted into your program will become part of the code and part of the data lines.
The program editor will autoindent when you press enter to match the indentation of the previous line. So before you type the DATALINES (or CARDS) statement make sure to tab back to the first column. Then as you type the actual lines of data they will start in column 1 also.
You can tell SAS/Studio to convert the tabs into spaces so you don't get those tab characters inserted into your program files by changing your preferences to enable the Substitute spaces for tabs option.
That will prevent tabs from accidentally being added to your program files. And since they are not part of the file then SAS/Studio cannot accidentally send them to SAS as part of the data.
You also need to check how you are seeing REGION. Currently you are always setting REGION to western. Indenting the Code properly can help with noticing that also.
Either keep the IF/THEN statemen ton a single line.
data WORK.GEO;
infile datalines;
input City $20.;
if City='Tulsa' then State = 'OK';
Region='Central';
if City='Los Angeles' then State = 'CA';
Region='Western';
datalines;
Tulsa
Los Angeles
Bangor
;
Of if you want to split it to multiple lines then move the semicolon that marks the end to a new line.
data WORK.GEO;
infile datalines;
input City $20.;
if City='Tulsa' then
State = 'OK'
;
Region='Central';
if City='Los Angeles' then
State = 'CA'
;
Region='Western';
datalines;
Tulsa
Los Angeles
Bangor
;
To have the REGION depend on the CITY then you might want to use DO/END block as the statement that the THEN condition runs.
data WORK.GEO;
infile datalines;
input City $20.;
if City='Tulsa' then do;
State = 'OK';
Region='Central';
end;
if City='Los Angeles' then do;
State = 'CA';
Region='Western';
end;
datalines;
Tulsa
Los Angeles
Bangor
;
... View more