Help using Base SAS procedures

proc transpose with two id variables

Accepted Solution Solved
Reply
Super Contributor
Posts: 301
Accepted Solution

proc transpose with two id variables

Hi everyone, after doing proc freq to a demog dataset I obtain new4f:

                         agex            treat       Sex           COUNT

                          13-24           drug         F                4

                          13-24           drug         M                2

                          13-24           PLA          F                2

                          13-24           PLA          M                4

                          less than 13    drug         F                2

                          less than 13    drug         M                2

                          less than 13    PLA          F                1

                          less than 13    PLA          M                2

Then, after doing proc sort and proc transpose I would expected the next datase *:

proc sort data=new4f out=new4fs;

by agex;

run;

proc transpose data=new4fs out=new4fst (drop=_label_ _name_);

by agex;

id treat sex;

var count;

run;

I would expected somethign like :

*dataset new4fst

agex                   drugf   drugm      plaf   plam

13-24                       4        2        2     4

less than 13              2      2          1     2  

but, windows sas log shown the next error: 

151  by agex ;

152  id treat sex;

              ---

              22

                 -

                 200

ERROR 22-322: Expecting ;.

ERROR 200-322: The symbol is not recognized and will be ignored.

what I am doing wrong?

Thanks in advance.

V


Accepted Solutions
Solution
‎04-02-2012 08:45 PM
Super Contributor
Posts: 1,636

proc transpose with two id variables

how about:

data have;

input agex $20.  treat $      Sex $          COUNT;

cards;

     13-24           drug         F                4

     13-24           drug         M                2

     13-24           PLA          F                2

     13-24           PLA          M                4

     less than 13    drug         F                2

     less than 13    drug         M                2

     less than 13    PLA          F                1

     less than 13    PLA          M                2

  ;

run;

data temp;

  set have;

  two=cats(treat,sex);

run;

proc transpose data=temp out=want(drop=_Smiley Happy ;

by agex;

var count;

id two;

run;

proc print;run;

              

                                            drug    drug

                Obs    agex              F       M     PLAF    PLAM

 

                 1     13-24               4       2       2       4

                 2     less than 13      2       2       1       2

Linlin

View solution in original post


All Replies
Solution
‎04-02-2012 08:45 PM
Super Contributor
Posts: 1,636

proc transpose with two id variables

how about:

data have;

input agex $20.  treat $      Sex $          COUNT;

cards;

     13-24           drug         F                4

     13-24           drug         M                2

     13-24           PLA          F                2

     13-24           PLA          M                4

     less than 13    drug         F                2

     less than 13    drug         M                2

     less than 13    PLA          F                1

     less than 13    PLA          M                2

  ;

run;

data temp;

  set have;

  two=cats(treat,sex);

run;

proc transpose data=temp out=want(drop=_Smiley Happy ;

by agex;

var count;

id two;

run;

proc print;run;

              

                                            drug    drug

                Obs    agex              F       M     PLAF    PLAM

 

                 1     13-24               4       2       2       4

                 2     less than 13      2       2       1       2

Linlin

Super User
Posts: 10,041

Re: proc transpose with two id variables

It is very strange. I tested your code. No problem.

data have;
input agex $20.  treat $      Sex $          COUNT;
cards;
     13-24           drug         F                4
     13-24           drug         M                2
     13-24           PLA          F                2
     13-24           PLA          M                4
     less than 13    drug         F                2
     less than 13    drug         M                2
     less than 13    PLA          F                1
     less than 13    PLA          M                2
  ;
run;



 

proc transpose data=have out=want(drop=_:) ;
by agex;
var count;
id treat sex;
run;


Ksharp

Valued Guide
Posts: 765

Re: proc transpose with two id variables

hi ... two ID variables, online doc does say "one or more" ...

ID variable(s);

variable(s) names one or more variables whose formatted values are used to form the names of the variables in the output data set.

and ...

When you specify multiple ID variables, conformance to the SAS variable naming convention will be imposed on the components of the variable name, using the formatted value of each ID variable, and also on the name composed from the ID variable values and the PREFIX, DELIMITER, and SUFFIX options. The resulting name will be truncated to a length appropriate for the VALIDVARNAME option setting.

nice solution that doesn't require the prior concatenation of the variable values

Respected Advisor
Posts: 3,799

Re: proc transpose with two id variables

One or more is new feature in SAS 9.2.

Super Contributor
Posts: 301

Re: proc transpose with two id variables

It works to me too. Thanks Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 6121 views
  • 6 likes
  • 5 in conversation