BookmarkSubscribeRSS Feed
qkaiwei
Calcite | Level 5

I have a table of data cleaning rules in one excel sheet, with variables: table_name, statement, like the following:

table_name statement

------------------------------------

a        if ..... then .....

b        if birth_date=. then birth_date=input(substr(id,3,8)),yymmdd10.)

The excel file will be modifed by our customer, new data cleaning rules will be added or modified into it. During the ETL process, all rules will in the xls file will be loaded and checked syntax, and then take effect by a SAS macro.

The question is: for an undeclared vairable in a data set. the substr function does not give an error message showing the varible doesn't exist, but create a new one. so the above step of syntax checking will mleiss some errors.

Thanks!

2 REPLIES 2
Tom
Super User Tom
Super User

SAS will generate notes to log about uninitialized variables.  You need to search for that when checking your SAS log for errors.

26   data _null_;

27     x=substr(y,3);

28   run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).

      27:12

NOTE: Variable y is uninitialized.

DanielSantos
Barite | Level 11

Hi.

You have to understand that no variable are created inside the datastep at runtime.

Datastep is processed in two distinct phases, compile and runtime.

It's at compile time that the layout(s) of the destination dataset(s) are defined, not at runtime.

The interpreter will scan the code and allocate every variable referenced in the code (on a memory area known as Program Data Vector, or PDV, that will output entirely or partially to the destination dataset(s)), sometimes doing some assumptions about type and length of new variables that aren't what you expected, hence the use of LENGHT statement to guide SAS interpreter to the right assumptions.

So when the code runs, everything is pretty well defined in terms of variables, lengths and types.

In you're case the SAS interpreter has allocated a new variable (and defaulted to numeric size 😎 before the run time phase because it has seen the reference to it at compiler time. Hope the explanation is clear.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt

sas-innovate-2024.png

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.

 

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