i want to utilize the proc sql to compute the value. the studyid need to be replaced by 'cats(study,id)'.
usubjid = cats(the newly studyid,'-','subjid')
but the proc always use the The original studyid in dm_raw.
the data dm_raw:
ID | studyid | subjid | study |
1 | 250 | 001 | 20200515 |
2 | 250 | 002 | 20200515 |
3 | 250 | 003 | 20200515 |
4 | 250 | 004 | 20200515 |
the procedure:
proc sql;
create table dm as
select cats(study,id) as studyid,
cats(studyid,'-',subjid) as usubjid
from dm_raw;
Please do ALWAYS post your data in a data step with datalines, so we can be sure of variable types and other attributes, and the real contents of your dataset.
In this case, "study" looks like a date, so it may be that the CATS() function does not yield the expected result.
Also, ALWAYS use the proper subwindow for posting code ("little running man" right next to the one indicated, which is for logs):
Your code as posted contained a "funny" semicolon, causing a syntax ERROR.
If you need to use a newly created variable in further operations, use the CALCULATED keyword:
proc sql;
create table dm as
select
cats(study,id) as studyid,
cats(calculated studyid,'-',subjid) as usubjid
from dm_raw
;
quit;
please try below code
proc sql;
create table dm as
select cats(study,id) as studyid,
cats(cats(study,id),'-',subjid) as usubjid
from dm_raw;
quit;
Please do ALWAYS post your data in a data step with datalines, so we can be sure of variable types and other attributes, and the real contents of your dataset.
In this case, "study" looks like a date, so it may be that the CATS() function does not yield the expected result.
Also, ALWAYS use the proper subwindow for posting code ("little running man" right next to the one indicated, which is for logs):
Your code as posted contained a "funny" semicolon, causing a syntax ERROR.
If you need to use a newly created variable in further operations, use the CALCULATED keyword:
proc sql;
create table dm as
select
cats(study,id) as studyid,
cats(calculated studyid,'-',subjid) as usubjid
from dm_raw
;
quit;
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!
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.
Ready to level-up your skills? Choose your own adventure.