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

Hello,

 

I have a dataset "nh.weekday1" that contains many variables starting with "dr1" such as "dr1drs" and "dr1_tak", I want to rename those variables starting with "wkdy", so they become "wkdydrs" and "wkdy_tak". My code and log are below. Could you please tell me what went wrong and how to fix it?

 

Thank you!

 

log.PNG

proc sql noprint;
   select cats(name,"=",tranwrd(name,"dr1","wkdy")) into :renames separated by " "
   from dictionary.columns
   where libname="NH" 
     and memname="weekday1"
     and name like "dr1";
quit;

proc datasets library=nh nolist;
    modify weekday1;
    rename &renames;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @knighsson,

 

In addition to the wrong case of "weekday1" you missed the wildcard character (%) in the LIKE condition:

and name like "dr1%"

which could also be written as

and name eqt "dr1"

(analogous for upcase(name), if needed).

 

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

Keep in mind that memname, like libname, is uppercase in the DICTIONARY tables. For most values in name, this will also be true, so you should convert it with UPCASE and compare with "DR1".

knighsson
Obsidian | Level 7

Thank you for your help! however, it is still not working.log.PNG

PaigeMiller
Diamond | Level 26

Your SQL log says "NOTE: No rows selected". So your WHERE clause is not finding any hits in the table.

 

Most likely you don't have the proper capitalization. MEMNAME and NAME should be all capital letters.

--
Paige Miller
knighsson
Obsidian | Level 7
Thank you!
FreelanceReinh
Jade | Level 19

Hello @knighsson,

 

In addition to the wrong case of "weekday1" you missed the wildcard character (%) in the LIKE condition:

and name like "dr1%"

which could also be written as

and name eqt "dr1"

(analogous for upcase(name), if needed).

 

knighsson
Obsidian | Level 7
Thank you so much!! This is it!

Thank you!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1404 views
  • 3 likes
  • 4 in conversation