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

Hi All,

 

I have came across following expression.

 

IF 0 then set abc;

how does this if 0 then set statement works

request you to explain with examples

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Well, 0 is false so the SET statement never executes.  You would get the same result by coding:

 

if 5=4 then set abc;

 

However, the statement still has an effect over the results of the DATA step.  SAS executes DATA steps in two phases.  During the first phase, it looks through all the statements, checks for syntax errors, and sets up storage space for all the variables that the DATA step will process.  Just the presence of the SET statement (even if it never executes) forces SAS to define all the variables that are part of ABC.  All the variable names, lengths, types, etc. will become part of the new data set being constructed.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Well, 0 is false so the SET statement never executes.  You would get the same result by coding:

 

if 5=4 then set abc;

 

However, the statement still has an effect over the results of the DATA step.  SAS executes DATA steps in two phases.  During the first phase, it looks through all the statements, checks for syntax errors, and sets up storage space for all the variables that the DATA step will process.  Just the presence of the SET statement (even if it never executes) forces SAS to define all the variables that are part of ABC.  All the variable names, lengths, types, etc. will become part of the new data set being constructed.

V_R
Fluorite | Level 6 V_R
Fluorite | Level 6

Thanks a lot for quick response

AndrewHowell
Moderator

The "if 0 then set" logic ensures that the code compiles (prepares variables, etc), but it never executes.

 

It's a very effective way of ensuring the structure of your target data set mimics the structure of your source data set, even if your source data set structure changes over time.

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
  • 3 replies
  • 12374 views
  • 14 likes
  • 3 in conversation