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

Hi,

 

I want to transpose my data such that it converts as follows: 

 

 Before  
ID198519861987
1345
2456
3567

 

 After 
119863
119874
119885
219864
219875
219886
319865
319876
31988

7

 

 

Suggestions, please.

Cheers,

AMalik

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

What are your sas variable names? 1985, 1986 etc. are not valid names in sas.

 

You can use proc transpose to get the wanted result, probably with one more step to get the year out of the _NAME_;

 

Try it and post your code and results in case of any issue.

View solution in original post

4 REPLIES 4
Shmuel
Garnet | Level 18

What are your sas variable names? 1985, 1986 etc. are not valid names in sas.

 

You can use proc transpose to get the wanted result, probably with one more step to get the year out of the _NAME_;

 

Try it and post your code and results in case of any issue.

Amalik
Calcite | Level 5

Thanks, I was just not using valid SAS name

Kurt_Bremser
Super User

Post your REAL data (pure numbers are NOT valid SAS names for columns), in the form of a data step, so we can easily recreate the dataset for testing, as it is. All other methods do not convey important information about the dataset in question.

Use the macro provided in https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to convert a dataset to a data step, if you have trouble writing that data step on your own.

Post the resulting code either in a "little running man" or {i} window, as both keep formatting an content. Posting code or data text in the main posting window will invariably mangle the content.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

If before looks like:

id _1985 _1986 _1987 - note the underscore to make them valid variable names then:

proc transpose data=have out=want;
  by id;
  var _:;
run;

Should work.  If ID is text then you can also do:

proc transpose data=have out=want;
  by id;
  var _numeric_;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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