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

Hi,

ive the following Data-Set:

 

YearbevV01V02V03Vn
 4063400739971464120...
2019 388937502220...
20204063400351033971900...

 

What I want is: Transpose all variables except of the empty line. The Var Bev should has a static value over all rows.

 

Year20192020bev
V01388935104063400
V02375033974063400
V03222019004063400
Vn

 

Ive tried it with this Code. The Result looks fine, but it doesnt creates the column Bev. Would be great to get some help! Thank you!

 

proc transpose data=test Name=Kontonummer präfix=Jahr out=test;
id Jahr;
var v01-v89;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You will need an additional step to set bev:

data have;
infile datalines dlm=" " dsd truncover;
input Year bev V01 V02 V03;
datalines;
 4063400 7399 7146 4120
2019  3889 3750 2220 
2020 4063400 3510 3397 1900
;

proc sql noprint;
select max(bev) into :bev from have;
quit;

proc transpose
  data=have
  out=trans (rename=(_name_=year))
  prefix=Y_
;
var V:;
id year;
run;

data want;
set trans;
bev = &bev;
run;

Note:

  • Data is presented as a data step with datalines, which makes it ver easy for everyone reading this to recreate the dataset without second guessing attributes or content. Please do so yourself in the future.
  • How you determine the value for bev may be different (e.g. from the first observation of have).

 

View solution in original post

3 REPLIES 3
ballardw
Super User

Except for the special variable like _name_ that might be added by proc transpose it will not create new values. You have to either populate that Bev value prior to the transpose or after, whichever makes more sense or is easiest.

Kurt_Bremser
Super User

You will need an additional step to set bev:

data have;
infile datalines dlm=" " dsd truncover;
input Year bev V01 V02 V03;
datalines;
 4063400 7399 7146 4120
2019  3889 3750 2220 
2020 4063400 3510 3397 1900
;

proc sql noprint;
select max(bev) into :bev from have;
quit;

proc transpose
  data=have
  out=trans (rename=(_name_=year))
  prefix=Y_
;
var V:;
id year;
run;

data want;
set trans;
bev = &bev;
run;

Note:

  • Data is presented as a data step with datalines, which makes it ver easy for everyone reading this to recreate the dataset without second guessing attributes or content. Please do so yourself in the future.
  • How you determine the value for bev may be different (e.g. from the first observation of have).

 

Konkordanz
Pyrite | Level 9

Its working! Thank you so much! So far I didnt work with proc sql, but obviously its pretty powerful 😉 Thx!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1377 views
  • 2 likes
  • 3 in conversation