DATA Step, Macro, Functions and more

Proc transpose query

Reply
Frequent Contributor
Frequent Contributor
Posts: 87

Proc transpose query

[ Edited ]

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.

Valued Guide
Posts: 628

Re: Proc transpose query

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;
Super User
Super User
Posts: 9,829

Re: Proc transpose query

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;
Frequent Contributor
Posts: 118

Re: Proc transpose query

Try this...

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

 

Hope this helps.

Contributor
Posts: 49

Re: Proc transpose query

@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;

Ask a Question
Discussion stats
  • 4 replies
  • 123 views
  • 0 likes
  • 5 in conversation