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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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