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

Dear All,

 

Can anyone help me with the below query ?

 

I have a dataset as below:

 

ID          TIME         SAMPLE           TEST ID

101         1hour          BLOOD              

101          2 hour        URINE                 

102          30min         blood                    

103          30min          blood                   

103          1 hour         urine

103           2 hour         blood

103           3 hour         urine

 

For the above data i need to assign TESTID values as some test1, test2, test3 per ID, per TIME and per sample. Desired output is as below:

 

ID          TIME         SAMPLE           TEST ID

101         1hour          BLOOD           TEST1

101         1hour          BLOOD           TEST2 

101         1hour          BLOOD           TEST3

101          2 hour        URINE             TEST 1

101          2 hour        URINE             TEST 2

101          2 hour        URINE             TEST 3

102          30min         blood              TEST 1

102          30min         blood              TEST 2 

102          30min         blood              TEST 3   

103          30min          blood             TEST 1

103          30min          blood             TEST 2

103          30min          blood             TEST 3    

103          1 hour         urine              TEST 1

103          1 hour         urine              TEST 2

103          1 hour         urine              TEST 3

103           2 hour         blood             TEST 1

103           2 hour         blood             TEST 2

103           2 hour         blood             TEST 3

103           3 hour         urine              TEST 1

103           3 hour         urine              TEST 2

103           3 hour         urine              TEST 3

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    test_id='ADB12PL';
    output;
    test_id='ADP13LM';
    output;
    test_id='DEF99SE';
    output;
run;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
data want;
    set have;
    do i=1 to 3;
        test_id=cats('TEST',i);
        output;
    end;
run;
--
Paige Miller
r3570
Obsidian | Level 7

Thanks Miller,

But I have a doubt here..

what if there are some values like ADB12PL, ADP13LM, DEF99SE which are to be assigned for TEST ID instead of test1, test2 and test3 ?

PaigeMiller
Diamond | Level 26

@r3570 wrote:

 

what if there are some values like ADB12PL, ADP13LM, DEF99SE which are to be assigned for TEST ID instead of test1, test2 and test3 ?


Explain this, please. Show an example.

--
Paige Miller
r3570
Obsidian | Level 7

Output required as below:

 

ID          TIME         SAMPLE           TEST ID

101         1hour          BLOOD          ADB12PL

101         1hour          BLOOD          ADP13LM

101         1hour          BLOOD          DEF99SE

101          2 hour        URINE            ADB12PL

101          2 hour        URINE            ADP13LM

101          2 hour        URINE            DEF99SE

102          30min         blood              ADB12PL

102          30min         blood              ADP13LM

102          30min         blood              DEF99SE

103          30min          blood            ADB12PL

103          30min          blood            ADP13LM

103          30min          blood            DEF99SE   

103          1 hour         urine              ADB12PL

103          1 hour         urine              ADP13LM

103          1 hour         urine            DEF99SE

103           2 hour         blood            ADB12PL

103           2 hour         blood            ADP13LM

103           2 hour         blood            DEF99SE

103           3 hour         urine              ADB12PL

103           3 hour         urine              ADP13LM

103           3 hour         urine            DEF99SE

PaigeMiller
Diamond | Level 26
data want;
    set have;
    test_id='ADB12PL';
    output;
    test_id='ADP13LM';
    output;
    test_id='DEF99SE';
    output;
run;
--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 549 views
  • 2 likes
  • 2 in conversation