BookmarkSubscribeRSS Feed
statadm
Fluorite | Level 6
I'm looking for a fast way to do this. I need to add the following to the end of all variables in the dataset:

"_3mo"

so that

ID = ID_3mo

Thanks!
8 REPLIES 8
Flip
Fluorite | Level 6
This will work.

proc sql;
select cat(name, ' = ', cats(name, '_3mo' )) into :renstr separated by ' ' from
dictionary.columns where libname = 'WORK' and memname='FMIN';
quit;

data new;
set fmin (rename = (&renstr));
run;
statadm
Fluorite | Level 6
There are three of us here and we can't get this to work. We constantly get the message that there are no rows, which means no observations are brought in.

I think we must be missing something... Message was edited by: statadm
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest you relax the WHERE clause. The code presumes that you have a SAS file identified in the WHERE clause by the LIBNAME and the MEMNAME variables which must either have been created in this SAS session or referenced with a prior LIBNAME command.

Share what code you are attempting to use and do so in a POST reply as a SAS log.

Scott Barry
SBBWorks, Inc.
Flip
Fluorite | Level 6
Make sure you run the SQL after you have created the data set with the variables you want to rename.
statadm
Fluorite | Level 6
Thanks to everyone, it is working now.

I didn't realize that the libname and memname had to be UPCASE. I'm obviously new to proc sql.

Thanks again!
Peter_C
Rhodochrosite | Level 12
statadm
it's not so much about sql as about the data it was using.
Have a look at the underlying data. Search on the support.sas.com website (most pages have a search box) for dictionary.columns, in product documentation. It will refer you to page titled "Programming with the SQL Procedure: Accessing SAS System Information by Using DICTIONARY Tables" at http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/a001385596.htm describing many of these dictionary tables, and pointing out that they are also available as "sashelp views". Although you cannot proc print the dictionary.something tables, you can refer to their sashelp.v{name} in proc contents and proc print.
So, to print the first few lines of dictionary.tables, [pre]proc print data= sashelp.vtable(obs=10);
run;[/pre] Or, when running SAS directly
(with Enterprise Guide drill through the server list to libraries, SASHELP and pick VCOLUMN)
[without Enterprise Guide, you can drill through the SAS Explorer into SASHELP library and open the item "Vcolumn"]
It might take longer to load than that proc print of the first 10 lines, but it is worth the time to experience and discover the extensive nature of the information these sashelp.v{name} aka dictionary tables, offer

PeterC
statadm
Fluorite | Level 6
Thanks Peter for helping me to understand.
data_null__
Jade | Level 19
No need to read any records just use &renstr in PROC DATASETS

[pre]
proc datasets library=...;
modify ...;
rename &renstr;
run;
[/pre]

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 8 replies
  • 21698 views
  • 2 likes
  • 5 in conversation