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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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