BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10
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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

View solution in original post

3 REPLIES 3
Ksharp
Super User

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;
novinosrin
Tourmaline | Level 20

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;
lillymaginta
Lapis Lazuli | Level 10
Thank you, I was trying to replace the variables with the correct names as Ksharp suggested

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1843 views
  • 2 likes
  • 3 in conversation