Please run this code:
data have;
input client code $;
cards;
1 A
1 B
2 A
3 A
3 C
3 D
4 A
5 A
5 B
;
run;
data int;
set have (where=(code ne 'A')) ;
val = 1;
run;
proc transpose
data=int
out=codes (drop=_name_)
;
by client;
id code;
var val;
run;
data want;
merge
have (
in=a
where=(code = 'A')
)
codes
;
by client;
if a;
A = 1;
drop code;
run;
proc print data=want noobs;
run;
I get this result:
client B C D 1 1 . . 2 . . . 3 . 1 1 4 . . . 5 1 . .
Why is variable A missing from the dataset want?
Even the log does not have it:
52
53 data want;
54 merge
55 have (
56 in=a
57 where=(code = 'A')
58 )
59 codes
60 ;
61 by client;
62 if a;
63 A = 1;
64 drop code;
65 run;
NOTE: There were 5 observations read from the data set WORK.HAVE.
WHERE code='A';
NOTE: There were 3 observations read from the data set WORK.CODES.
NOTE: The data set WORK.WANT has 5 observations and 4 variables.
This happens on SAS 9.4M5 on AIX 7.1
Please tell me I'm not going crazy!
Well, in= variables get dropped automatically. So even if you change the value of an in= variable, that won't be sufficient to keep it.
It's possible that this is just an oversight that you were reusing the variable. Maybe this combination will strike you as unusual:
if a;
A=1;
Well, in= variables get dropped automatically. So even if you change the value of an in= variable, that won't be sufficient to keep it.
It's possible that this is just an oversight that you were reusing the variable. Maybe this combination will strike you as unusual:
if a;
A=1;
Of course it was an oversight on my part. Reusing the simple name A was the reason.
This time I really needed another pair of eyeballs.
Thanks very much, I'm still sane.
I always try to use variable names that start with IN for the IN= dataset option. So IN=in1 or IN=in_master instead of things like IN=A.
It is still possible to have name conflicts, but at least then the reason might be easier to spot.
@Tom wrote:
I always try to use variable names that start with IN for the IN= dataset option. So IN=in1 or IN=in_master instead of things like IN=A.
It is still possible to have name conflicts, but at least then the reason might be easier to spot.
<grin>
I'm used to use simple names like a,b,c for my in= variables because in a production environment there never are such names in datasets. But with simple example code ...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.