BookmarkSubscribeRSS Feed
UPRETIGOPI
Obsidian | Level 7

Hi deal all

I have attached an excel file with the original sample data file and the desired data table that I want. I thought I could produce the desired data table with proc transpose but I could not produce it. I am not that good at data manipulation using sas datstep and procs.

I have a variable named SP_ID which I want to use that as the ID variable. The ID variable (SP_ID) has three values, L, N, S. There is another variable identifying variable (ID) that I want to use as the by variable. Actually I want to use ID and DATE variable as the BY Vairble like below

 

Proc transpose data=Have out=trans_have;

by ID DATE;

var ........;

ID SP_ID;

Run;

 

When you take a look at the attacheed excel data file, you will understand what I really want. I think it requires a series of Proc transpose to get to the desired data table that I want which I have included in the excel file. Please help me on this. I would greatly appreciate your kind assistance in this regard. I think there are number of different techniques in SAS that one can use to get to the desired data table that I want. Please include all those dat step and procs that can be used to produce the desired data table. Thanks

 

Very Respectfully

 

Chandra   

 

 

 

 
2 REPLIES 2
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values. So any code built on a different data set may not work for your data.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Reeza
Super User

@UPRETIGOPI wrote:

Please include all those dat step and procs that can be used to produce the desired data table. Thanks


 

PROC TRANSPOSE - one to make it a long file. Use a Data step to create the new column ID's using the combination of the old variable name and your L/N/S variables. Then use a second transpose to make it wide again. 

 

Since this looks like a report - PROC REPORT/TABULATE are also options but they'd work better if the data was long not wide. In general storing data in a long format is a better structure to store and process the data. 

 

And there's always manual processing using either a data step or proc sql. Or you can use pre-canned macros, there's a good one in a paper called "A Better Way to Transpose" written by some frequent users on here.

 

 

 

 

 

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 837 views
  • 0 likes
  • 3 in conversation