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

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:

IDstudyidsubjidstudy
125000120200515
225000220200515
325000320200515
425000420200515

the procedure:

proc sql;

  create table dm as 

    select cats(study,id) as studyid,

               cats(studyid,'-',subjid) as usubjid

    from dm_raw;

 

Don’t stop pursuing to be a better version of yourself, even if only a little change
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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):

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

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;

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
hyo_tree
Fluorite | Level 6
thank you Jagadishkatam. i think the option 'caculated' is the better choice.,
Don’t stop pursuing to be a better version of yourself, even if only a little change
Kurt_Bremser
Super User

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):

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

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;
hyo_tree
Fluorite | Level 6
Thanks for your clarification
Don’t stop pursuing to be a better version of yourself, even if only a little change

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!

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
  • 4 replies
  • 943 views
  • 0 likes
  • 3 in conversation