Hello Friends,
I have the attached data set with variables name with special character in csv file such as Q19.1, Q20.1, Q22.1, Q22.2, Q22.3 etc. How can I import these variables as SAS Standard column/variables name? Either in Proc import or in Data step.
Thank you in advance for your help.
Since it is a text file just use your own names when reading the data.
They don't have to be anything like the column headers.
data want;
infile "Sample_data.csv" dsd truncover firstobs=2;
input id $ var1-var11;
run;
You can also make sure to set VALIDVARNAME=V7 and then let PROC IMPORT try to convert the headers into valid names. But then you lose control over not only how the variables are named but also how they are defined.
@Akter wrote:
Hello Friends,
I have the attached data set with variables name with special character in csv file such as Q19.1, Q20.1, Q22.1, Q22.2, Q22.3 etc. How can I import these variables as SAS Standard column/variables name? Either in Proc import or in Data step.
Thank you in advance for your help.
Please see:
data example; infile datalines dlm=','; input ID :$8. Q19_1 Q20_1 Q22 Q22_1 Q22_2 Q22_3 Q22_4 Q22_5 Q22_6 Q22_7 Q22_8; datalines; 07-003,3,1,7,0,0,0,0,0,0,1,0 05-028,4,1,8,0,0,0,0,0,0,1,1 06-033,4,1,7,0,0,0,0,0,0,1,0 09-006,3,1,8,0,0,0,0,0,0,0,1 06-017,5,1,6,0,0,0,0,0,1,0,0 06-009,4,1,1,1,0,0,0,0,0,0,1 04-041,6,1,5,0,1,0,0,0,1,1,1 03-028,4,1,8,1,0,0,0,0,0,0,1 06-032,2,1,1,1,0,0,0,0,0,0,0 02-012,5,1,7,0,0,0,0,0,0,1,0 05-014,2,1,5,1,1,0,0,0,1,0,0 07-005,2,1,7,0,0,0,0,0,0,1,0 09-050,2,1,8,0,0,0,0,0,0,0,1 09-011,5,1,4,1,1,0,1,0,0,1,1 ;
So to read you data the INFILE statement would have the path and file name in quotes:
Infile "c:\folder\subfolder\sampledata.csv" dlm=',';
and you would not include the DATALINES portion.
Since it is a text file just use your own names when reading the data.
They don't have to be anything like the column headers.
data want;
infile "Sample_data.csv" dsd truncover firstobs=2;
input id $ var1-var11;
run;
You can also make sure to set VALIDVARNAME=V7 and then let PROC IMPORT try to convert the headers into valid names. But then you lose control over not only how the variables are named but also how they are defined.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.