Help using Base SAS procedures

Import .txt file of Survey Data into SAS

Reply
N/A
Posts: 0

Import .txt file of Survey Data into SAS

I have a txt file (.asc) of Survey data (more than 100 variables Q1-Q100), with variable label and variable coding list as separated parts in the txt file (.asc).

Is there any systematic methods to read this file? I mean, label all variables, and coding each variable in a systematic way rather than re_label and code (proc format) each variable one by one in SAS?


Thanks in advance.
N/A
Posts: 0

Re: Import .txt file of Survey Data into SAS

that sounds like a commercial service that should have been commissioned/provided along with the data.

For variable-coding you would want to create cntlin= data set for proc format. For re-labelling columns you would want to generate the "variable = 'label' " text for proc datasets.

There are probably features in the data that help you recognise the separate types of data/information.
Use these criteria to create data sets from which you can build the relevant metadata with code like : [pre]
%let infile = your.survey.asc ;
data yourLib.data_data_part( label="data loaded %now")
yourLib.label_metadata( label="from &infile" keep= name label )
yourLib.variable_codes( label="&infile var codes" keep= name value label type )
;
infile "&infile" .......................... ;
.................
if {criteria defines variable label} then output yourLib.label_metadata ;
else
if {criteria defines variable codes} then output yourLib.variable_codes ;
else
if {criteria defines data } then output yourLib.data_data_part ;
run;[/pre] That is just schematic... What follows is code you might use for building and applying variable labels from label metadata [pre]
proc sql noprint ;
select trim(name) !! '=' !! quote(trim(label))
into :labelling separated by ' '
from label_metadata( keep= name label )
;
quit;
proc datasets library =yourLib nolist ;
modify data_data_part ;
Label &label_metadata ;
run;
quit;[/pre]

Good Luck

PeterC
Ask a Question
Discussion stats
  • 1 reply
  • 277 views
  • 0 likes
  • 1 in conversation