BookmarkSubscribeRSS Feed
Nrjn7
Fluorite | Level 6
IDEventx_tpointx_datex_scoredis_datey_tpointy_scorey_date
1a314thfeb45thmarch   
1a320thfeb55thmarch   
1b   5thmarch361stmarch
2a31stmarch51stapril   
2b   1stapril3415thmarch
3a31st April61stmay   
3a37thapril71stmay   

 

I want to get the following table, please assist?

 

IDx_tpointx_date1x_date2x_score1x_score2dis_datey_tpointy_scorey_date
1314thfeb20thfeb455thmarch361stmarch
231stmarch 5 1stapril3415thmarch
331stapril7thapril671stmay3  

 

6 REPLIES 6
r_behata
Barite | Level 11

Here is one way :

 

data want(rename=(x_tpoint_=x_tpoint));
	array x_date_[3] $ x_date1-	x_date3;
	array x_score_[3] $ x_score1-x_score3;

	x_tpoint_=.;
	do _n_=1 by 1 until(last.id);
		set have;
		by id;

	 	x_date_[_n_]=x_date; 
	 	x_score_[_n_]=x_score; 

		if x_tpoint ^=. then x_tpoint_=x_tpoint;
	end;

keep ID	x_tpoint_	x_date1	x_date2	x_score1	x_score2	dis_date	y_tpoint	y_score	y_date;
run;
ballardw
Super User

Should ask @Nrjn7 what the maximum number of dates or scores will ever appear within a value of ID.

 

Just because a small shown example only shows 3 as likely there may actually be 5, 10, 15 or some other number.

Nrjn7
Fluorite | Level 6

@ballardw @r_behata That's a really good question. For a given ID, the events are repeated instruments. Meaning, For study ID 1, they could have more than one Event a (in  this example: there's only 2 event a for studyid 1 but there could be more). would the code work if the event "a" or "b" were more for given studyid. for every event they would have dates.

 

Thank you

r_behata
Barite | Level 11

@Nrjn7  The code can be slightly modified to adjust to your needs. Have you tried running the code with your actual data to see what happens ?

 

The sample output you have shown has  fixed columns such as : x_score1,x_score2. If your data has more than 2 events , say 5 or 10 does the output columns needs to change accordingly. If yes, show us some samples.

 

 

Nrjn7
Fluorite | Level 6

@r_behata thanks for responding.

 

Using the code, this is the result I'm currently getting.

idx_date1x_datet2x_score1x_score2x_tpointdis_datey_tpointy_scorey_date
114thfeb20thfeb45..361stmarch
21stmarch 5...3415thmarch
31stapril7thapril673... 

 

So, the columns for score and date are dependent on how many event per study ID there is.

 

For example, for StudyID 1 he could have 'n' number of event 'a' or 'n' number of event b, (x_tpoint, y_tpoint and dis_date) is always fixed)

so, I have this table

ideventx_tpointx_datex_scoredis_datey_tpointy_datey_score
1a31stjan48   
1a32ndjan38   
1a33rdjan58   
1'n' th a       
1b   834thjan6
1b   835thjan7
1'n' th b       

 

The events are repeated instruments so ID 1 can have 'n' number of a's and b's.

 

I want the table below:

ideventx_tpointx_date1x_date2x_date3x_date'n'x_score1x_score2x_score3x_score'n'

 

          

 

I couldn't fit the y_score y_date but the idea is the same.

 

Really appreciate the help.

 

r_behata
Barite | Level 11

I am not quite sure how you want these rows to be represented in your output. They seem to be having different dates unlike the first sample you have shown.

 

1 b       8 3 4thjan 6
1 b       8 3 5thjan 7

 

Would you like the  y_score, y_date to be converted as Y_Score1,Y_Score2...YScoren and Y_date1,Y_Date2...Y_Daten ?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1480 views
  • 0 likes
  • 3 in conversation