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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.