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

Dear All,
Can I please seek your help on how to achieve this?
For example, I would like turn data X into data Y.

Thanks a lot.

Data X Data Y
id  grp  id  grp 
1  A 1  A
1  B 1  B
2  A 1 C
2  C 2  A
3  A 2 B
3  B 2  C
3  C 3  A
4  C 3  B
  3  C
  4  A
  4  B
  4  C

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ
data x;
input id grp $1.;
datalines;
1 A
1 B
2 A
2 C
3 A
3 B
4 C
;

proc freq
	data = x noprint;
		tables id * grp / 	sparse 
							out = y (drop = count percent);
run;
id grp 
1 A 
1 B 
1 C 
2 A 
2 B 
2 C 
3 A 
3 B 
3 C 
4 A 
4 B 
4 C 

I prefer the SPARSE statement with PROC FREQ to do things like this.

View solution in original post

2 REPLIES 2
maguiremq
SAS Super FREQ
data x;
input id grp $1.;
datalines;
1 A
1 B
2 A
2 C
3 A
3 B
4 C
;

proc freq
	data = x noprint;
		tables id * grp / 	sparse 
							out = y (drop = count percent);
run;
id grp 
1 A 
1 B 
1 C 
2 A 
2 B 
2 C 
3 A 
3 B 
3 C 
4 A 
4 B 
4 C 

I prefer the SPARSE statement with PROC FREQ to do things like this.

Miracle
Barite | Level 11

Thanks @maguiremq for your quick reply.
I was thinking something like datastep by reading a macro variable containing all the unique grp then using do loop to repeat for every row but I dunno how exactly.
This is much easier and should do for now.

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
  • 2 replies
  • 1007 views
  • 1 like
  • 2 in conversation