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

An example program is followed. i am wondering why the last observation in dataset C had a value of 'B' in the column OUTCOME?

Thank you all!!

 

 

DATA A;

INPUT OBS $ OUTCOME $;
CARDS;
1 A
2 B
;
RUN;


DATA B;
INPUT OBS $ RESULT $;
CARDS;
1 1
2 2
3 .
;
RUN;
DATA C;
SET A(IN = A) B(IN = B);
IF A THEN DATASET = 'A';
IF B THEN DO;
DATASET = 'B';
IF RESULT = '1' THEN OUTCOME = 'A';
ELSE IF RESULT = '2' THEN OUTCOME = 'B';
END;
RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

First, keep in mind that all variables in datasets named in a set (or merge) statement are automatically retained.

So, when the second dataset B is being read, outcome will always be retained from the previous iteration of the data step.

Since the next-to-last observation in B has a result of '2', outcome is set to 'B'; In the last observation, result is missing, so none of the conditons in the do/end block is met, and outcome stays at value 'B'.

 

BTW stop coding in uppercase-only. Interpreters and compilers understand lowercase since the 60's, and it makes code easier to read.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

First, keep in mind that all variables in datasets named in a set (or merge) statement are automatically retained.

So, when the second dataset B is being read, outcome will always be retained from the previous iteration of the data step.

Since the next-to-last observation in B has a result of '2', outcome is set to 'B'; In the last observation, result is missing, so none of the conditons in the do/end block is met, and outcome stays at value 'B'.

 

BTW stop coding in uppercase-only. Interpreters and compilers understand lowercase since the 60's, and it makes code easier to read.

TristanTang
Calcite | Level 5

Thanks for the answer.

For me, uppercase is easier to read. Anyway, thank you for your suggestion!!

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