Hi Everyone,
Very new to sas. I just imported a csv file and was wondering how I can rename a column. Thanks for your help. This was my code:
data pracitce.new1 (rename=(nationalid=nid));
set practice.new
run;
proc print data= practice.new1;
run;
The imported file is now under practice.new. Is there a way to just modify the column on the parent file without creating a new file? I got this error:
98 data pracitce.new1 (rename=(nationalid=nid));
ERROR: Libref PRACITCE is not assigned.
99 set practice.new
100 run;
ERROR: File WORK.RUN.DATA does not exist.
101
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
102 proc print data= practice.new1;
103 run;
NOTE: No observations in data set PRACTICE.NEW1.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
You did not assign your libref PRACITCE right 🙂
Your rename statement looks right if you want to use the variable name nid in your data step.
If you want to use the variable name nationalid and then rename the variable in your output data set simply do
data pracitce.new1;
set practice.new
rename nationalid=nid
run;
Thank you. How do I correctly assign the practice folder as my library? I thought I did that already before when I created the library folder... thanks again.
Like this 🙂
%let path = insertyourpathhere;
libname practice "&path";
As to your question - yes you can rename a variable in a dataset without making a new dataset ... using PROC DATASETS:
proc datasets libname=practice; /*or pracitce if that is correct spelling*/
modify new;
rename nationalid=nid;
run;
quit;
Looks like a typo?
Practice vs pracitce
Yes, it was a typo! Thank you everyone.
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.
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.