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

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1154 views
  • 2 likes
  • 2 in conversation