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

Hii i have a dataset like this

idreasfreq count
1317
1623
1756
1933
11024
2364
2623
2734
2864
21043

 and the output i want is can anyone help me how to solve this ?

reasid=1id=2
31764
62323
75634
83364
1024

43

 thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
proc sort data=have out=_have;
by reas;
run;

proc transpose data=_have out=want prefix=ID ;
by reas;
id id;
var freqcount;
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
proc sort data=have out=_have;
by reas;
run;

proc transpose data=_have out=want prefix=ID ;
by reas;
id id;
var freqcount;
run;
Aayushi_17
Quartz | Level 8
thank you all
ShiroAmada
Lapis Lazuli | Level 10

You can try data step or using sql


/* data step */
proc sort data=have;
  by reas;
run;

data want;
  length
  reas id_1 id_2 8;
  merge 
  have(where=(id=1) rename=(freqcount=id_1) in=a)
  have(where=(id=2) rename=(freqcount=id_2) in=b);
  by reas;
  drop id;
run;

/* PROC SQL */
proc sql;
  create table want3 as
  select 
  coalesce(a.reas,b.reas) as reas,
  a.freqcount as id_1,
  b.freqcount as Id_2
  from have(where=(id=1)) a full join 
  have(where=(id=2)) b 
  on a.reas=b.reas;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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