For example: Data should contain the following variables.
CUSTOMER_ID, AGE, MOB_NO.
but the variable names in the csv are like
cusTomer No, aGe, Number
All the variable names are always differing due the the guy delivering me the data.
Now what I want is regardless of what data I receive I should always discard the first row and assign my own variables without even considering what variables were there in the CSV.
This is helpful when we know that data is always same only the variable names differ so we need not to go and change variable names in excel and then save it and then import it, rather we just import the file with the pre-defined variable names that we always want.
That's why you never use PROC IMPORT for text files, but write the data step yourself.
Copy the data step code created by PROC IMPORT from the log, and change the variable names.
@Kirito1 wrote:
If the data is in .xls format then what we can do.
Save as a csv file and read it with a data step.
@Kirito1 wrote:
Can we use infile for that without considering what file format is data in?
No, infile and input statement must match the structure of the file.
I just want to change variable names while importing a csv without doing the following
RENAME = (old1=new1 old2=new2 .... oldk=newk);
is there a way through which I could change variable names without considering what variables are there in the csv file.
@Kirito1 wrote:
I just want to change variable names while importing a csv without doing the following
RENAME = (old1=new1 old2=new2 .... oldk=newk);
is there a way through which I could change variable names without considering what variables are there in the csv file.
There is absolutely NO need to RENAME variables when reading a csv file. A csv file is read with INFILE and INPUT in a DATA step, and the variable names are defined in the INPUT statement.
@Kirito1 wrote:
I just want to change variable names while importing a csv without doing the following
RENAME = (old1=new1 old2=new2 .... oldk=newk);
is there a way through which I could change variable names without considering what variables are there in the csv file.
If the position of the variables are constant and only the names are set randomly, you could ignore the names (getnames=no) during proc import and use the rename option.
INFILE and INPUT in a DATA step can be used for text files; Excel files need PROC IMPORT or LIBNAME EXCEL/XLSX.
The results of reading Excel files directly are inconsistent at best; it is always better to save the data to a text file and read that with a DATA step.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.