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

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