DATA Step, Macro, Functions and more

Renaming a column after importing data from csv

Reply
Frequent Contributor
Posts: 77

Renaming a column after importing data from csv

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

PROC Star
Posts: 757

Re: Renaming a column after importing data from csv

You did not assign your libref PRACITCE right Smiley Happy

 

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;
Frequent Contributor
Posts: 77

Re: Renaming a column after importing data from csv

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.

PROC Star
Posts: 757

Re: Renaming a column after importing data from csv

Like this Smiley Happy

 

%let path = insertyourpathhere; 
libname practice "&path";
Trusted Advisor
Posts: 1,022

Re: Renaming a column after importing data from csv

 

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;

Super User
Posts: 19,822

Re: Renaming a column after importing data from csv

Looks like a typo?

 

Practice vs pracitce

Frequent Contributor
Posts: 77

Re: Renaming a column after importing data from csv

Yes, it was a typo! Thank you everyone.

Ask a Question
Discussion stats
  • 6 replies
  • 191 views
  • 1 like
  • 4 in conversation