BookmarkSubscribeRSS Feed
sandyrcl
Calcite | Level 5

 

Hi,

 

I have a dataset with many ID's and each id has multiple events(models in the case of the sample data). I want the output data set to have one observation per subject, count the maximum events per id per model and create a flagging variable(a,b, c and so on) for each occurence of the event and the corresponding values of year and state for that event. Any help would be appreciated. Thanks in advance.

 

Sample data:

data test;
input id $ model $ year state $;
datalines;
A100 XYZ 1999 CA
A100 XYZ 2010 TX
A200 PQR 2013 IL
A200 XYZ 2015 IL
;
RUN

Output needed:

DATA TEST2;
INPUT id $ axyz bxyz xyzayr xyzbyr xyzast $ xyzbst $ apqr pqrayr pqrast $ ;
datalines;
A100 1 1 1999 2010 CA TX . . .
A200 1 . 2015 . IL . 1 2013 IL
;
RUN;

Thank you.

 

3 REPLIES 3
Reeza
Super User

Thats gonna be hell to work with after. 

 

That being said it looks like two proc transposes that are then merged by ID. You can calculate the 1's afterwards by scanning the values. 

 

 

PGStats
Opal | Level 21

Please tell us what you intend to achieve with such a data structure. Give us a chance to propose an alternative that avoids the complications inherent to this route.

PG
TomKari
Onyx | Level 15

I vociferously support the previous two posters in recommending that you look for an alternative.

 

Are you familiar with the concept of a summary dataset, that would have your summary information at the id level, that you could then join to a lower level dataset using common keys?

 

Tom

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
  • 3 replies
  • 922 views
  • 2 likes
  • 4 in conversation