DATA Step, Macro, Functions and more

FILE statement in DATA _NULL_ (no quick answer from Google)

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

FILE statement in DATA _NULL_ (no quick answer from Google)

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;


Accepted Solutions
Solution
‎12-06-2011 06:20 PM
PROC Star
Posts: 7,360

FILE statement in DATA _NULL_ (no quick answer from Google)

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


All Replies
Solution
‎12-06-2011 06:20 PM
PROC Star
Posts: 7,360

FILE statement in DATA _NULL_ (no quick answer from Google)

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.

Super User
Super User
Posts: 6,499

Re: FILE statement in DATA _NULL_ (no quick answer from Google)

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;

....

New Contributor
Posts: 3

FILE statement in DATA _NULL_ (no quick answer from Google)

Thanks for the beyond_original_question answer

New Contributor
Posts: 3

FILE statement in DATA _NULL_ (no quick answer from Google)

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;

Super User
Super User
Posts: 6,499

FILE statement in DATA _NULL_ (no quick answer from Google)

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;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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