BookmarkSubscribeRSS Feed
anjgupta
Calcite | Level 5

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

7 REPLIES 7
art297
Opal | Level 21

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

anjgupta
Calcite | Level 5

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.

art297
Opal | Level 21

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

anjgupta
Calcite | Level 5

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

Thanks!

Anjali

art297
Opal | Level 21

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

anjgupta
Calcite | Level 5

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

art297
Opal | Level 21

Look again .. I just added it

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
  • 7 replies
  • 1046 views
  • 0 likes
  • 2 in conversation