BookmarkSubscribeRSS Feed
wriccar
Fluorite | Level 6

Hello fellow SAS users,

 

Hoping someone can help me write a code for a relatively simple (but tedious) procedure. My data set includes dates (beginning and ending) during which an error occurred for a given observation. About 41% of Groups have errors in multiple periods. The data looks like this:

 

Group NameTypeError TypePeriod BegPeriod End
AAABBB1F1/1/200312/31/2003
AAABBB1R4/1/20046/30/2004

 

I need each Group to correspond to only a single observation, so that line of data needs to capture all the different error periods. Something like this: 

Group NameTypeError TypePeriod BegPeriod EndError Type2Period Beg2Period End2
AAABBB1F1/1/200312/31/2003R4/1/20046/30/2004

 

Some groups have only a single error period, some have many. I was using a pretty rudimentary program using lags but it was not efficient. Any help would be greatly appreciated. 

 

6 REPLIES 6
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

@wriccar your sample data should included some samples that your request address.

When the sample size is to small the results will not always include possible constraints that need to be considered.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why do you need the second example?  The data as stored in the first example is a better method of storing the data.

The only time it might be useful is for a report, in which case three proc transposes, then merge back together by group name.

wriccar
Fluorite | Level 6

The end goal of what I'm asking is because I need to merge with a second dataset, and identify if the period from that dataset corresponds to an error period. If there are multiple observations for the same Group, then the merge does not take in all of those different error periods. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please show concrete examples, presenting test data in the form of a datastep for each input dataset:
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

I do not see how merging with one record rather than multiple records would be any different, its exactly the same data, if date fits into one of the time periods then it merges onto that row??

wriccar
Fluorite | Level 6

I solved my problem so no need for further replies. Thank you!

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Please post your solution so the community benefits also.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1145 views
  • 2 likes
  • 3 in conversation