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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 715 views
  • 0 likes
  • 2 in conversation