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

Hi SAS experts,

 

when I ran the following program, I found y was automatically retained for x=4 in data test2. What happed?

 

Thanks!

 

data test;
    input x y;
    cards;
    1 .
    3 .
    ;
run;

data test1;
    input x;
    cards;
    3
    4
    ;
run;
data test2;
    set test(in=a)
        test1(in=b);
    if b then do;
        if x=3 then y=4;
    end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Any variable that comes from any SAS data set is automatically retained.  Since Y comes from a SAS data set, it is automatically retained.

 

A small complication:  when switching data sets (from TEST to TEST1 in the SET statement), Y is reset to missing.  You can see that by adding this statement after the SET statement:

 

put Y;

 

But once Y is set to 4, it remains 4 (unless changed by subsequent programming statements).  As @PGStats said, reading an observation from TEST1 does not replace Y. 

View solution in original post

5 REPLIES 5
PGStats
Opal | Level 21

There is no y variable in dataset test1 so the value of y isn't reset to missing when test1 is read.

PG
fbl204653
Obsidian | Level 7

Thanks!

PGStats
Opal | Level 21

My answer is not quite right. You should mark @Astounding answer as the correct answer instead.

PG
Astounding
PROC Star

Any variable that comes from any SAS data set is automatically retained.  Since Y comes from a SAS data set, it is automatically retained.

 

A small complication:  when switching data sets (from TEST to TEST1 in the SET statement), Y is reset to missing.  You can see that by adding this statement after the SET statement:

 

put Y;

 

But once Y is set to 4, it remains 4 (unless changed by subsequent programming statements).  As @PGStats said, reading an observation from TEST1 does not replace Y. 

fbl204653
Obsidian | Level 7
Thanks!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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