data long;
input enrolid1 date1 : mmddyy10. x1 x2 x3 x4;
format date1 mmddyy10.;
datalines;
4 5/5/2009 y n y n
4 5/5/2009 y y y y;
run;
data wide;
input variable def
datalines;
x1 head
x2 neck
x3 stomach
x4 colon;
run; I have the following datasets, I am trying to define each of the xs in data long from data wide and looking for the following output :
enrolid1 date1 head neck stomach colon
4 5/5/2009 y n y n
4 5/5/2009 y y y y
Just rename the variable name .
data long;
input enrolid1 date1 : mmddyy10. (x1 x2 x3 x4) ($);
format date1 mmddyy10.;
datalines;
4 5/5/2009 y n y n
4 5/5/2009 y y y y
;
run;
data wide;
input variable $ def $;
datalines;
x1 head
x2 neck
x3 stomach
x4 colon
;
run;
proc sql noprint;
select catx('=',variable,def) into : list separated by ' '
from wide;
quit;
proc datasets library=work nolist nodetails;
modify long;
rename &list ;
quit;
Just rename the variable name .
data long;
input enrolid1 date1 : mmddyy10. (x1 x2 x3 x4) ($);
format date1 mmddyy10.;
datalines;
4 5/5/2009 y n y n
4 5/5/2009 y y y y
;
run;
data wide;
input variable $ def $;
datalines;
x1 head
x2 neck
x3 stomach
x4 colon
;
run;
proc sql noprint;
select catx('=',variable,def) into : list separated by ' '
from wide;
quit;
proc datasets library=work nolist nodetails;
modify long;
rename &list ;
quit;
Hello @lillymaginta
The question isn't making a clean sense of a clear logical objective of a look up. But,FWIW
data wide;
input variable $ def $;
datalines;
x1 head
x2 neck
x3 stomach
x4 colon
;
run;
proc transpose data=wide out=t(drop=_name_);
var variable;
id def;
run;
data want;
set long;
if _n_=1 then set t;
array j head--colon;
array k x:;
do i=1 to dim(j);
j(i)=k(i);/*I am not sure if this is what you want, the look up flow should be rather neat */
end;
drop i x:;
run;
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.