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,

How can I transform this dataset A dataset using proc transpose in * dataset:

A dataset

                    agex            treat       Sex    COUNT    count2

                        13-24           drug         F       4         6

                        13-24           drug         M       2         6

                        13-24           PLA          F       2         6

                        13-24           PLA          M       4         6

                        less than 13    drug         F       2         4

                        less than 13    drug         M       2         4

                        less than 13    PLA          F       1         3

                        less than 13    PLA          M       2         3

* dataset

                Obs    agex        drugF   drugM drugT     PLAF    PLAM plaT

                 1     13-24               4       2       6            2       4            6

                 2     less than 13      2       2       4            1       2            3

          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;

  length two $8;

  two=cats(treat,sex);

run;

proc transpose data=temp out=want(drop=_:) ;

by agex;

var count;

id two;

run;

data want;

   retain agex drugf drugm drugt plaf plam plat;

   set want;

   drugt=drugm+drugf;

   plat=plam+plaf;

  run;

  proc print;run;

       obs    agex            drugf    drugm    drugt    plaf    plam    plat

 

       1     13-24               4        2        6        2       4       6

       2     less than 13      2        2        4        1       2       3

View solution in original post

1 REPLY 1
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;

  length two $8;

  two=cats(treat,sex);

run;

proc transpose data=temp out=want(drop=_:) ;

by agex;

var count;

id two;

run;

data want;

   retain agex drugf drugm drugt plaf plam plat;

   set want;

   drugt=drugm+drugf;

   plat=plam+plaf;

  run;

  proc print;run;

       obs    agex            drugf    drugm    drugt    plaf    plam    plat

 

       1     13-24               4        2        6        2       4       6

       2     less than 13      2        2        4        1       2       3

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
  • 1 reply
  • 617 views
  • 0 likes
  • 2 in conversation