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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 944 views
  • 1 like
  • 2 in conversation