Help using Base SAS procedures

How do Combine variables in to one space delimited variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

How do Combine variables in to one space delimited variable

I am trying to take a column that has multipul values and create one var. I need them combined in to one before line.

DATA HAVE

item1            item2       item2       item3
TYPE            BILCYCLE    DBILC01     JOB    
RUN              BILCYCLE    DBILC01     ANY    
AFTER          BILCYCLE    DBILC01     -NONE- 
BEFORE       BILCYCLE    DBILC01     QARBCDAF
BEFORE       BILCYCLE    DBILC01     QARBCD14
BEFORE       BILCYCLE    DBILC01     QARBC1CF
BEFORE       BILCYCLE    DBILC01     QBILCDAS
BEFORE       BILCYCLE    DBILC01     QBILCD20
EVENT          BILCYCLE    DBILC01     QASCHED.DBILC01
COND(S)       BILCYCLE    DBILC01     CCCHK RC(1:4095) FAIL
TYPE             ABCDEFG1    DBILC0A     JOB    
RUN               ABCDEFG1    DBILC0A     ANY    
AFTER           ABCDEFG1    DBILC0A     -NONE- 
BEFORE        ABCDEFG1    DBILC0A     ANYNAME1
BEFORE        ABCDEFG1    DBILC0A     SOMENAM1
BEFORE        ABCDEFG1    DBILC0A     ANTHNAM1
EVENT           ABCDEFG1    DBILC0A     QASCHED.DBILC01
COND(S)        ABCDEFG1    DBILC0A     CCCHK RC(1:4095) FAIL

 

I only want to end up with one line for each different item1, if it has multipul BEFORE jobs I want to be combined into
one var "new ITEM"

DATA WANT
item1            item2              item2           newITEM
TYPE            BILCYCLE    DBILC01     JOB    
RUN              BILCYCLE    DBILC01     ANY    
AFTER          BILCYCLE    DBILC01     -NONE- 
BEFORE       BILCYCLE    DBILC01     QARBCDAF QARBCD14 QARBC1CF QBILCDAS QBILCD20
EVENT          BILCYCLE    DBILC01     QASCHED.DBILC01
COND(S)       BILCYCLE    DBILC01     CCCHK RC(1:4095) FAIL
TYPE             ABCDEFG1    DBILC0A     JOB    
RUN              ABCDEFG1    DBILC0A     ANY    
AFTER           ABCDEFG1    DBILC0A     -NONE- 
BEFORE        ABCDEFG1    DBILC0A     ANYNAME1 SOMENAM1 ANTHNAM
EVENT           ABCDEFG1    DBILC0A     QASCHED.DBILC01
COND(S)        ABCDEFG1    DBILC0A     CCCHK RC(1:4095) FAIL


Accepted Solutions
Solution
‎07-11-2017 12:30 PM
Trusted Advisor
Posts: 1,128

Re: How do Combine variables in to one space delimited variable

 

Please try this untested code, before that sort the data using proc sort

 

data want;
length newitem $100.;
set have;
by item1 item2 item3 ;
retain newitem;
if first.item1 then newitem='';
if item3 ne '' then newitem=catx(' ', item3,newitem);
run;
Thanks,
Jag

View solution in original post


All Replies
Solution
‎07-11-2017 12:30 PM
Trusted Advisor
Posts: 1,128

Re: How do Combine variables in to one space delimited variable

 

Please try this untested code, before that sort the data using proc sort

 

data want;
length newitem $100.;
set have;
by item1 item2 item3 ;
retain newitem;
if first.item1 then newitem='';
if item3 ne '' then newitem=catx(' ', item3,newitem);
run;
Thanks,
Jag
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 142 views
  • 2 likes
  • 2 in conversation