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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

 

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

1 REPLY 1
Jagadishkatam
Amethyst | Level 16

 

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 958 views
  • 2 likes
  • 2 in conversation