BookmarkSubscribeRSS Feed
JaneNYC
Calcite | Level 5

Hi-

I’m having trouble with getting the correct output using proc transpose.  In the data set below you’ll notice for the first two observations there are missing by group values ID_CODE and Office.

data have;

input ID_CODE Office $ Name $ Rate;

datalines;

. . G19 1

. . G20 0

848 PHX G21 0.5

848 PHX L1 0

848 PHX L3 .

848 PHX P5 1

1084 PHX P6 0.5

1084 PHX P7 1

1084 PHX P8 1

1084 PHX P10 0

1084 PHX S33 0.5

1084 PHX S35 0

1084 PHX WB15 .

1084 PHX WB22 .

1084 PHX WB25 1

;

My program.

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

var  Rate;

by ID_CODE Office;

id Name;run;

When I run the program above this is my output.

ID_CODEOfficeG19G20G21L1L3P5P6P7P8P10S33S35WB15WB22WB25
. ...............
848PHX..0.50.1.........
1084PHX......0.51100.50..1

I need to drop the first missing observation but keep the first two transposed vars G19 and G20.

ID_CODEOfficeG19G20G21L1L3P5P6P7P8P10S33S35WB15WB22WB25
848PHX..0.50.1.........
1084PHX......0.51100.50..1

Any feedback is appreciated. Thanks. 

5 REPLIES 5
AncaTilea
Pyrite | Level 9

Hi,

Using your code, you could add one more option:

proc transpose data=have  out=want (drop=_: where = (id_code ne .));

var  Rate;

by ID_CODE Office;

id Name;

run;

JaneNYC
Calcite | Level 5

Hi there. Thanks for your feedback.  your modification did not work. I still get the same result. the vars G19 and G20 drop. I need to keep both of them in the data set even though when the data set is transposed their values turn to missing. 

AncaTilea
Pyrite | Level 9
09:48 Tuesday, December 11, 2012

Obs  ID_CODE  Office  G19  G20  G21  L1  L3  P5   P6  P7  P8  P10  S33  S35  WB15  WB22  WB25

  1 848PHX..   0.5   0   .   1   ..   .   ......
  21084PHX....   .   .  0.5   1   1   0   0.5   0..1

This is what I get when I run the code below.

proc transpose data=have  out=want (drop=_: where = (id_code ne .));

var  Rate;

by ID_CODE Office;

id Name;

run;

You could also do an additional data step:

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

var  Rate;

by ID_CODE Office;

id Name;

run;

data really_want;

     set want(where = (id_code ne .));

run;

ArtC
Rhodochrosite | Level 12

Jane,

Did you make sure that the WHERE= was applied to the OUT= data set?

art297
Opal | Level 21

Jane: What version of SAS are you running and can you post the code you tried?  On 9.3, using Anca's code, I get the same results as Anca gets.

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
  • 913 views
  • 0 likes
  • 4 in conversation