BookmarkSubscribeRSS Feed
byeh2017
Quartz | Level 8

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

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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;
byeh2017
Quartz | Level 8

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.

PeterClemmensen
Tourmaline | Level 20

Like this 🙂

 

%let path = insertyourpathhere; 
libname practice "&path";
mkeintz
PROC Star

 

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;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Reeza
Super User

Looks like a typo?

 

Practice vs pracitce

byeh2017
Quartz | Level 8

Yes, it was a typo! Thank you everyone.

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
  • 6 replies
  • 3504 views
  • 1 like
  • 4 in conversation