DATA Step, Macro, Functions and more

order of statements within datastep

Reply
Contributor
Posts: 47

order of statements within datastep

Hi,

Unintentionally I created code that, within 1 data step, had a set of 'input' statements

(e.g

pat_age =   input(pat_age, dot_or_ninetynine.)

)

followed by infiling the data.  As I didn't receive 'uninitilized errors' it's made me curious how SAS handles statements about variables that don't yet exist -   in that the code for reading in raw data follows statements referring to the data.  Or the variable is created 'later' in the statements and isn't read in with the raw data.

Any references to explain the order of operations for statements?

Hope that's clearer than mud,

Anjali

PROC Star
Posts: 7,363

order of statements within datastep

I would have to think that you either had another infile statement before that or that you received an error in your log.

The behavior, which is executable, is defined on the lower part of the page at:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146932.htm

Contributor
Posts: 47

order of statements within datastep

Yes, I stand corrected.  The INFILE precedes all else - but I'm still curious if/when the formatting will be applied.  Example:

**********************************************************************

322     data stout.&state._BirthData01 ;                /* data read in to become formatted data */

323        length bc 8.;

324        infile stbirth LRECL=&birthreclength linesize=&birthlinesize

325        N=&birthLinesPerObs missover;

326        %create_code_statements(birthfmt, pramsvars) /*informats for formatting birth file */

MPRINT(CREATE_CODE_STATEMENTS):   mat_age = input(mat_age, dot_or_ninetynine.);

MPRINT(CREATE_CODE_STATEMENTS):   pnc_mth = input(pnc_mth, month_pncf.);

MPRINT(CREATE_CODE_STATEMENTS):   momcig = input(momcig, momlbsf.);

327        %create_input_string_fmt(statevars, birth)

MPRINT(CREATE_INPUT_STRING_FMT):   input #1 @0001 yy4_dob ? yy4f. @;

MPRINT(CREATE_INPUT_STRING_FMT):   if _error_ or yy4_dob=. then yy4_dob=.U ;

MPRINT(CREATE_INPUT_STRING_FMT):   _error_=0;

MPRINT(CREATE_INPUT_STRING_FMT):   input #1 @0005 b_state ? $char2. @;

MPRINT(CREATE_INPUT_STRING_FMT):   input #1 @0007 certnum ? $char6. @;

MPRINT(CREATE_INPUT_STRING_FMT):   input #1 @0013 void ? $char1. @;

MPRINT(CREATE_INPUT_STRING_FMT):   input #1 @0026 tb ? 4. @;

...  

328  %create_code_statements( birthcalc, pramsvars ) 

   (infdob and momdob created at some point here)

MPRINT(CREATE_CODE_STATEMENTS):   mat_age = year(infdob) - year(momdob);

***********************************************************************************

In that temporal order - will the initial lines:

MPRINT(CREATE_CODE_STATEMENTS):   mat_age = input(mat_age, dot_or_ninetynine.);

MPRINT(CREATE_CODE_STATEMENTS):   pnc_mth = input(pnc_mth, month_pncf.);

MPRINT(CREATE_CODE_STATEMENTS):   momcig = input(momcig, momlbsf.);

have no effect as they precede the creation of the variables to be formatted?

Thank you.

PROC Star
Posts: 7,363

order of statements within datastep

I think you might find the following paper quite helpful in understanding what is going on under the hood:

http://www2.sas.com/proceedings/sugi28/189-28.pdf

Contributor
Posts: 47

order of statements within datastep

Thank you.  I'm sure the explanation is in there - might need a 'dummies' version to truly get it.

Thanks!

Anjali

PROC Star
Posts: 7,363

Re: order of statements within datastep

I wouldn't call the following "PDV for Dummies", but you might find it an easier read .. although I'd recommend reading both and more.

http://support.sas.com/resources/papers/proceedings09/136-2009.pdf

Contributor
Posts: 47

Re: order of statements within datastep

I am not seeing the link/attachment for the 2nd recommended article.  Thank you.

PROC Star
Posts: 7,363

Re: order of statements within datastep

Look again .. I just added it

Ask a Question
Discussion stats
  • 7 replies
  • 127 views
  • 0 likes
  • 2 in conversation