Help using Base SAS procedures

How can i rename variables for tab delimited file?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

How can i rename variables for tab delimited file?

*Set up title on line 1;
TITLE1 "STATS 301(glee217/749750841): &sysuserid";
*Specify SAS library for storing permanent SAS datasets;
LIBNAME stats301 "H:\stats301\A2";

proc import out=Work.Pumpkin1
datafile="H:\stats301\A2\Pumpkin.txt"
DBMS=tab REPLACE;
getnames=no;
datarow=1;
run;

i imported the data by using the SAS code above,

 

 

and next i wanted to rename variables but it only gave one variable for the "first_name".

(Here is the code for renaming variables)

**renaming variables;
data Work.Pumpkin1;
set work.Pumpkin1;
rename var1=first_name
var2=last_name
var3=age
var4=category
var5=date
var6=judge1
var7=judge2
var8=judge3
var9=judge4
var10=judge5;
run;


 

 

And the error is saying:


WARNING: The variable var2 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable var3 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable var4 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable var5 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable var6 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable var7 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable var8 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable var9 in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable var10 in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: There were 7 observations read from the data set WORK.PUMPKIN1.
NOTE: The data set WORK.PUMPKIN1 has 7 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 

how can i fix this problem? i would attach the file for my output too.

Attachment

Accepted Solutions
Solution
‎08-18-2017 05:10 PM
Trusted Advisor
Posts: 1,444

Re: How can i rename variables for tab delimited file?

[ Edited ]

As said already and looking at your text file - it is not tab delimited buy comma delimited.

When you define DBMS=TAB the whole row enters one variable.

 

Change your code t, from

proc import out=Work.Pumpkin1
datafile="H:\stats301\A2\Pumpkin.txt"
DBMS=tab REPLACE;
getnames=no;
datarow=1;
run;

into:

proc import out=Work.Pumpkin1
datafile="H:\stats301\A2\Pumpkin.txt"
DBMS=dlm REPLACE;
Delimiter = ',';
getnames=no;
datarow=1;
run;

 

View solution in original post


All Replies
Contributor
Posts: 71

Re: How can i rename variables for tab delimited file?

Look at the note from the log:

 

NOTE: The data set WORK.PUMPKIN1 has 7 observations and 1 variables.

 

There's only one variable in the data set, probably var1. 

Occasional Contributor
Posts: 18

Re: How can i rename variables for tab delimited file?

Oh there must be something wrong in my code!

This is original txt file. And i need to create different variables,

which represent first name, last name, age, category, date, scores from 5 different judges.

 

Would you kindly help me out for this :/?

Super User
Super User
Posts: 6,718

Re: How can i rename variables for tab delimited file?

Your text file appears to be comma delimited, not tab delimited.

To read such a somple text file just define your variables. Attach any required INFORMATs or FORMATs. And then read the variable in.

data pumpkin;
  infile 'pumpkin.txt' dsd truncover ;
  length first_name last_name $40 age 8  category $8 date judge1-judge5 8;
  informat date mmddyy. ;
  format date yymmdd10. ;
  input first_name -- judge5 ;
run;

I prefer to display dates in YMD order to avoid the confusion that using either MDY or DMY order can cause. 

Super User
Super User
Posts: 6,718

Re: How can i rename variables for tab delimited file?

You cannot rename variables that do not exist. Most likely your file is NOT tab delimited. 

 

But why are you using PROC IMPORT if you already know what is in the file?  Just read the file directly.

 

Occasional Contributor
Posts: 18

Re: How can i rename variables for tab delimited file?

Oh there must be something wrong in my code!
This is original txt file. And i need to create different variables,
which represent first name, last name, age, category, date, scores from 5 different judges.

Would you kindly help me out for this :/?
i attached txt file on my different comment.
Solution
‎08-18-2017 05:10 PM
Trusted Advisor
Posts: 1,444

Re: How can i rename variables for tab delimited file?

[ Edited ]

As said already and looking at your text file - it is not tab delimited buy comma delimited.

When you define DBMS=TAB the whole row enters one variable.

 

Change your code t, from

proc import out=Work.Pumpkin1
datafile="H:\stats301\A2\Pumpkin.txt"
DBMS=tab REPLACE;
getnames=no;
datarow=1;
run;

into:

proc import out=Work.Pumpkin1
datafile="H:\stats301\A2\Pumpkin.txt"
DBMS=dlm REPLACE;
Delimiter = ',';
getnames=no;
datarow=1;
run;

 

Occasional Contributor
Posts: 18

Re: How can i rename variables for tab delimited file?

Thank you everyone! i worked it out!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 227 views
  • 2 likes
  • 4 in conversation