BookmarkSubscribeRSS Feed
ursula
Pyrite | Level 9

Hi there,

anyone can help?

 

data raw; 
input ID car D2 D3 D4 D5;  ** I have 100 more D variables in the real data **;
datalines;
101 1 100 300 -1 500
102 2 200 -1 400 600
103 3 -1 200 300 -1
;

run;

 

I wan:

ID car DX
101 1 100
101 1 300
101 1 500
102 2 200
102 2 400
102 2 600
103 3 200
103 3 300

 

Thanks,

12 REPLIES 12
novinosrin
Tourmaline | Level 20
data raw; 
input ID car D2 D3 D4 D5;  ** I have 100 more D variables in the real data **;
datalines;
101 1 100 300 -1 500
102 2 200 -1 400 600
103 3 -1 200 300 -1
;

run;

proc transpose data=raw out=want(drop=_name_);
by id car;
var  d:;
run;
ursula
Pyrite | Level 9

Thank you, but I do not want to include the -1.

novinosrin
Tourmaline | Level 20
ok try:

proc transpose data=raw out=want(where=(COL1>0) drop=_name_);
by id car;
var  d:;
run;
ursula
Pyrite | Level 9

when I run into my real data, the column "car" are all the same values, and COL1, COL2, what does the COL2 means?

Reeza
Super User

The code works on the sample data. How does your actual data differ from the sample data and post your code and log. 

 

 

ursula
Pyrite | Level 9

I have no Idea, why it has another column "COL2" and all are blank.

 

proc transpose data=Drug out =Drug_1 (where=(COL1>0) drop=_name_);
by ID VS;
var 😧 ;run;

 

it looks like only generate for one VS.

Reeza
Super User

If you look at the code we suggested, there's no VAR statement. 

 

ursula
Pyrite | Level 9

I tried to run without Var statement, it looks error. 

I think we do need the var statement.

 

Thanks for your time and support!

ursula
Pyrite | Level 9

I figured it out, because there are some ID has duplicate data. that's why it has COL2.

ursula
Pyrite | Level 9

Thanks for your time and support!

 

I will clean my raw data and rerun it again.

 

I'm sure it will work!

Reeza
Super User

Delete it after the TRANSPOSE, use a WHERE data set option.

 

 

Reeza
Super User

Did you try PROC TRANSPOSE?

proc transpose data=raw out=want;
by id car;
run;

@ursula wrote:

Hi there,

anyone can help?

 

data raw; 
input ID car D2 D3 D4 D5;  ** I have 100 more D variables in the real data **;
datalines;
101 1 100 300 -1 500
102 2 200 -1 400 600
103 3 -1 200 300 -1
;

run;

 

I wan:

ID car DX
101 1 100
101 1 300
101 1 500
102 2 200
102 2 400
102 2 600
103 3 200
103 3 300

 

Thanks,




 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 12 replies
  • 1072 views
  • 5 likes
  • 3 in conversation