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

 

 

 

if delflag=0 then output;
if happen=1 then delflag=1;

in the above two statement,

the lines with delflag=0 have been written to the want dataset and

how does the next if clause still truncate the rest of observations against the same id?

and even leave the first "happen=1" in the dataset?

 

 

I am trying to learn this logic.  your response is very appreicated.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Lulus,

 

Here is what happens with each observation of your example dataset when mohamed_zaki's data step is executed (focusing on the three lines of code starting with "if"):

ID seq happen   comment
1   1    0      delflag is set to 0, obs. (incl. delflag) is written to WANT due to OUTPUT statement
1   2    0      delflag is still 0 due to RETAIN, obs. is written to WANT
1   3    1      delflag is still 0, obs. is written to WANT, delflag is set to 1
2   1    0      delflag is set to 0, obs. is written to WANT
2   2    1      delflag is still 0, obs. is written to WANT, delflag is set to 1
2   3    0      delflag is still 1, hence obs. is not written to WANT
2   4    1      delflag is still 1, hence obs. is not written to WANT, delflag is set to 1

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hello @Lulus,

 

Here is what happens with each observation of your example dataset when mohamed_zaki's data step is executed (focusing on the three lines of code starting with "if"):

ID seq happen   comment
1   1    0      delflag is set to 0, obs. (incl. delflag) is written to WANT due to OUTPUT statement
1   2    0      delflag is still 0 due to RETAIN, obs. is written to WANT
1   3    1      delflag is still 0, obs. is written to WANT, delflag is set to 1
2   1    0      delflag is set to 0, obs. is written to WANT
2   2    1      delflag is still 0, obs. is written to WANT, delflag is set to 1
2   3    0      delflag is still 1, hence obs. is not written to WANT
2   4    1      delflag is still 1, hence obs. is not written to WANT, delflag is set to 1

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 791 views
  • 1 like
  • 2 in conversation