I have a SAS dataset TEST and i wanted to update st_nm_des column where the description is missing on a specific date 16JAN2018.
MD- Maryland and DE - Delaware
date | state | st_nm_des |
15JAN2018 | AL | ALABAMA |
16JAN2018 | MD | |
16JAN2018 | DE | |
17JAN2018 | CT | Connecticut |
18JAN2018 | FL | Florida |
19JAN2018 | ID | Idaho |
20JAN2018 | ME | Maine |
Can anyone please help
data have;
input date :date9. state $ st_nm_des :$11.;
format date date9.;
cards;
15JAN2018 AL ALABAMA
16JAN2018 MD .
16JAN2018 DE .
17JAN2018 CT Connecticut
18JAN2018 FL Florida
19JAN2018 ID Idaho
20JAN2018 ME Maine
run;
data want;
set have;
if date = '16JAN2018'd and state = 'MD' then st_nm_des = 'Maryland';
if date = '16JAN2018'd and state = 'DE' then st_nm_des = 'Delaware';
run;
Hello @jhh197,
Have you tried the STNAME or STNAMEL function?
Example:
data test;
input date :date9. state $ st_nm_des :$20.;
format date date9.;
cards;
15JAN2018 AL ALABAMA
16JAN2018 MD .
16JAN2018 DE .
17JAN2018 CT Connecticut
18JAN2018 FL Florida
19JAN2018 ID Idaho
20JAN2018 ME Maine
;
data test;
modify test;
where st_nm_des=' ';
st_nm_des=stnamel(state);
replace;
run;
data have;
input date :date9. state $ st_nm_des :$11.;
format date date9.;
cards;
15JAN2018 AL ALABAMA
16JAN2018 MD .
16JAN2018 DE .
17JAN2018 CT Connecticut
18JAN2018 FL Florida
19JAN2018 ID Idaho
20JAN2018 ME Maine
run;
data want;
set have;
if date = '16JAN2018'd and state = 'MD' then st_nm_des = 'Maryland';
if date = '16JAN2018'd and state = 'DE' then st_nm_des = 'Delaware';
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.