BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
  1. data in;
    infile datalines dlm='09'x;
    input id 1 num 3-4;
    datalines;
    2 12
    3 45
    3 74
    5 33
    5 12
    5 15
    ;
    run;



    I want output 

    IDNum
    212
    345,74
    533,12,15
    i
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ah, sorry. Missed a statement. There u go 🙂

 

data in;
infile datalines dlm='09'x;
input id 1 num 3-4;
datalines;
2 12
3 45
3 74
5 33
5 12
5 15
;

data want(drop=oldnum);
   set in(rename=(num=oldnum));
   length num $100;
   by id;
   num=catx(',', num, oldnum);
   if first.id then num=oldnum;
   if last.id then output;
   retain num;
run;

proc print data=want;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20
data in;
infile datalines dlm='09'x;
input id 1 num 3-4;
datalines;
2 12
3 45
3 74
5 33
5 12
5 15
;

data want(drop=oldnum);
   set in(rename=(num=oldnum));
   length num $100;
   by id;
   num=catx(',', num, oldnum);
   if first.id then num=oldnum;
   retain num;
run;

proc print data=want;
run;
BrahmanandaRao
Lapis Lazuli | Level 10

@BrahmanandaRao wrote:
  1. data in;
    infile datalines dlm='09'x;
    input id 1 num 3-4;
    datalines;
    2 12
    3 45
    3 74
    5 33
    5 12
    5 15
    ;
    run;



    I want output 

    IDNum
    212
    345,74
    533,12,15
    i


Hi dear

 

but i got output like below

 

Obs id num123456
212
345
345,74
533
533,12
533,12,15
PeterClemmensen
Tourmaline | Level 20

Ah, sorry. Missed a statement. There u go 🙂

 

data in;
infile datalines dlm='09'x;
input id 1 num 3-4;
datalines;
2 12
3 45
3 74
5 33
5 12
5 15
;

data want(drop=oldnum);
   set in(rename=(num=oldnum));
   length num $100;
   by id;
   num=catx(',', num, oldnum);
   if first.id then num=oldnum;
   if last.id then output;
   retain num;
run;

proc print data=want;
run;

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