data new2;
set new1;
length Reporting_INST_AT $4.;
length Reporting_INST_AM $4. ;
if FAC_NUM=842 and INST_AT = '1423' and INST_AM = '4110' then Reporting_FAC_NUM=976 and Reporting_INST_AT='4804' and Reporting_INST_AM='4805';
else if FAC_NUM=849 then Reporting_FAC_NUM=976 ;
else if FAC_NUM=664 and INST_AT ='1538' and INST_AM ='4113' then Reporting_FAC_NUM=942 and Reporting_INST_AT='4788' and Reporting_INST_AM='4790';
else if FAC_NUM=880 and INST_AM ='3905' then Reporting_FAC_NUM=953 and Reporting_INST_AM='4767';
else if FAC_NUM=731 and INST_AT ='3286' and INST_AM = '3986' then Reporting_FAC_NUM=975 and Reporting_INST_AT='4747' and Reporting_INST_AM='4751';
else if FAC_NUM=949 and INST_AT ='3917' and INST_AM ='4090' then Reporting_FAC_NUM=975 and Reporting_INST_AT='4752' and Reporting_INST_AM='4756';
else if FAC_NUM=956 then Reporting_FAC_NUM=947 ;
else if FAC_NUM=927 and INST_AT ='3707' and INST_AM = '4142' then Reporting_FAC_NUM=933 and Reporting_INST_AT='4773' and Reporting_INST_AM='4774';
else if FAC_NUM=933 and INST_AT ='1079' and INST_AM = '4414' then Reporting_FAC_NUM=933 and Reporting_INST_AT= '1079' and Reporting_INST_AM='4414';
else if FAC_NUM=933 and INST_AT ='4607' then Reporting_FAC_NUM=933 and Reporting_INST_AT='4607' ;
else if FAC_NUM =941 and INST_AT ='1343' and INST_AM ='4089' then Reporting_FAC_NUM=941 and Reporting_INST_AT='.' and Reporting_INST_AM='4089';
else if FAC_NUM =941 and INST_AT ='3883' and INST_AM ='4260' then Reporting_FAC_NUM=941 and Reporting_INST_AT='4799' and Reporting_INST_AM='4802';
else if FAC_NUM =941 and INST_AT ='4610' and INST_AM ='4672' then Reporting_FAC_NUM=941 and Reporting_INST_AT='4799' and Reporting_INST_AM='4802';
else if FAC_NUM =721 and INST_AT ='2177' and INST_AM ='3974' then Reporting_FAC_NUM=977 and Reporting_INST_AT='4819' and Reporting_INST_AM='4820';
else if FAC_NUM =819 and INST_AT ='2180' and INST_AM ='4118' then Reporting_FAC_NUM=977 and Reporting_INST_AT='4822' and Reporting_INST_AM='4823';
else if FAC_NUM =692 and INST_AT ='4784' and INST_AM ='4106' then Reporting_FAC_NUM=978 and Reporting_INST_AT='4830' and Reporting_INST_AM='4829';
else if FAC_NUM =693 and INST_AT ='1100' and INST_AM ='4105' then Reporting_FAC_NUM=978 and Reporting_INST_AT='4831' and Reporting_INST_AM='4832';
else if FAC_NUM =954 and INST_AT ='3943' and INST_AM ='4139' then Reporting_FAC_NUM=979 and Reporting_INST_AT='4836' and Reporting_INST_AM='4837';
else if FAC_NUM =960 and INST_AT ='4152' and INST_AM ='3975' then Reporting_FAC_NUM=979 and Reporting_INST_AT='4840' and Reporting_INST_AM='4839';
else if FAC_NUM =954 and INST_AT ='4014' and INST_AM ='4140' then Reporting_FAC_NUM=952 and Reporting_INST_AT='4844' and Reporting_INST_AM='4845';
else if FAC_NUM =898 and INST_AT ='1443' and INST_AM ='4056' then Reporting_FAC_NUM=980 and Reporting_INST_AT='4858' and Reporting_INST_AM='4857';
else if FAC_NUM =773 and INST_AT = '.' and INST_AM ='.' then Reporting_FAC_NUM=980 and Reporting_INST_AM='4860';
else if FAC_NUM=852 and INST_AT = '1444' and INST_AM ='3985' then Reporting_FAC_NUM=980 and Reporting_INST_AT='4865' and Reporting_INST_AM='4864';
else if FAC_NUM=628 and INST_AT = '1223' and INST_AM ='4238' then Reporting_FAC_NUM=981 and Reporting_INST_AT='4869' and Reporting_INST_AM='4868';
else if FAC_NUM=870 and INST_AT = '1239' and INST_AM ='4239' then Reporting_FAC_NUM=981 and Reporting_INST_AT='4871' and Reporting_INST_AM='4870';
else if FAC_NUM=629 then Reporting_FAC_NUM=981 ;
else Reporting_FAC_NUM=FAC_NUM and Reporting_INST_AT=INST_AT and Reporting_INST_AM=INST_AM;
run;With the above code I get blanks for Reporting_INST_AT and Reporting_INST_AM and 0 or 1 for Reporting_FAC_NUM
Would someone be able to please point out the reason for the same or give me some hints
I also get the message in the log:
Variable Reporting_INST_AT is uninitialized.
NOTE: Variable Reporting_INST_AM is uninitialized.
NOTE: There were 272 observations read from the data set WORK.NEW1.
NOTE: The data set WORK.NEW2 has 272 observations and 15 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
An explicit example of @JeffMaggio's suggestion:
else if FAC_NUM=664 and INST_AT ='1538' and INST_AM ='4113' then do; Reporting_FAC_NUM=942; Reporting_INST_AT='4788'; Reporting_INST_AM='4790'; end;
I really hate lines of code longer than 60 or so characters so put the dependent assignments one per line.
You need to change your syntax to:
if (conditions) then do; stmt; smtmt; stmt; end;
else if (conditions) then do; stmt; smtmt; stmt; end;
else if (conditions) then do; stmt; smtmt; stmt; end;
else if (conditions) then do; stmt; smtmt; stmt; end;
else do; stmt; stmt; stmt; end;
The data step isn't interpreting the "and"s the way you think it is.
thankyou
An explicit example of @JeffMaggio's suggestion:
else if FAC_NUM=664 and INST_AT ='1538' and INST_AM ='4113' then do; Reporting_FAC_NUM=942; Reporting_INST_AT='4788'; Reporting_INST_AM='4790'; end;
I really hate lines of code longer than 60 or so characters so put the dependent assignments one per line.
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!
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.