BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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=_:) ;

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

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

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=_:) ;

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

Ksharp
Super User

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

MikeZdeb
Rhodochrosite | Level 12

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

data_null__
Jade | Level 19

One or more is new feature in SAS 9.2.

michtka
Fluorite | Level 6

It works to me too. Thanks Smiley Happy

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 18059 views
  • 6 likes
  • 5 in conversation