BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TDub
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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.

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

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.

Tom
Super User Tom
Super User

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;

....

TDub
Calcite | Level 5

Thanks for the beyond_original_question answer

TDub
Calcite | Level 5

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;

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1189 views
  • 5 likes
  • 3 in conversation