BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

data sensitive;
input type1 $ type2 $ var1 $ var2 $ var3 $ var4 $;
cards;
t1 ta custid custname m mobile
;

 

With the dataset above, how can I transpose var1,var2,var3,and var4 only? The desired dataset should look like:

 

Var_need

custid

custname

m

mobile

 

Is it possible? Anyone can help? Thanks.

4 REPLIES 4
andreas_lds
Jade | Level 19

Using a loop and the output-statement:

data work.want;
   set work.sensitive;
   length Var_Need $ 8; /* important: must be equal to max vlength of var1-var4 */
   array vars var1-var4;
   
   do i = 1 to dim(vars);
      Var_Need = vars[i];
      output;
   end;

   keep Var_Need;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This is not complicated, what have you tried?  Have you for instance tried the tranpose procedure, which you may find useful in this case:

data sensitive;
  input type1 $ type2 $ var1 $ var2 $ var3 $ var4 $;
cards;
t1 ta custid custname m mobile
;
run;

proc transpose data=sensitive out=want;
  by type1 type2;
  var var:;
run;
ShiroAmada
Lapis Lazuli | Level 10

Try this...

proc transpose data=HAVE out=WANT;
  var VAR: ;
run;

 

Hope this helps.

soham_sas
Quartz | Level 8

@scb you can do it like below 

 

data sensitive;
input type1 $ type2 $ var1 $ var2 $ var3 $ var4 $;
cards;
t1 ta custid custname m mobile
;
run;

proc transpose data=sensitive out=want(drop=_name_ rename=(col1=var_need));
var var1-var4;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 756 views
  • 0 likes
  • 5 in conversation