I need people help me to explain what does the FILE statement do here and what is the purpose of this DATA step?
Thanks.
Tim
FILENAME TEMPMK '/home/.../TEMPMK';
DATA _NULL_;
FILE TEMPMK NOPRINT NOTITLE;
IF _N_ = 1 THEN DO;
SET HEADER;
RECORDS = &TOTRECS;
PUT FILETYPE &TAB RECORDS &TAB FILENAME &TAB
FILEID &TAB FILEYEAR &TAB ' ';
END;
ELSE DO;
SET COUNT;
PUT RECORDNO &TAB FIPS &TAB STATEAGN &TAB
DISTRICT &TAB &TABF &TAB
ImpDS &TAB
EXPLAIN;
END;
RUN;
The file statement is there so that when you use a put statement it will put the data into the file.
The purpose of the datastep appears to be to write a header record and some other data to a file.
The file statement is there so that when you use a put statement it will put the data into the file.
The purpose of the datastep appears to be to write a header record and some other data to a file.
I assume from the macro variable names the intent is a TAB delimited file.
Note that with the addition of the DSD and DLM options to the FILE statement you could probably get rid of the &TAB macro variable references. But what the purpose of &TABF macro variable is I can only guess perhaps to have any empty column?
filename tempmk dsd dlm="&tab";
...
PUT FILETYPE RECORDS FILENAME FILEID FILEYEAR ' ';
....
PUT RECORDNO FIPS STATEAGN DISTRICT &TABF ImpDS EXPLAIN;
....
Thanks for the beyond_original_question answer
But when I use dsd dlm="&tab" to run it, I found "+" was between the variables instead of TAB space. Any hint?
Could you also explain how the macro variable TAB was defined? You are right, &TABF does generate an empty column. But how "+(-1) '09'X" be resolved to a tab?
%LET TAB =+(-1) '09'X;
%LET TABF = '09'X;
The +(-1) is tell it to back over the extra space that it normally puts between variables when using this list mode style of put statement. The +(-1) is not needed when using DSD option. You do not want the cursor movement command in your delimiter, so you would want to set DLM='09'x in the FILE statement. (or you could use dlm=&tabf as it would be the same thing).
The use of &TABF is to have it put out two tabs with no space between them. To mimic that with DSD option you will need to make an empty char variable.
blank=' ';
PUT RECORDNO FIPS STATEAGN DISTRICT blank ImpDS EXPLAIN;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.