%let DorsHHFPath =/dorsshare/HHFit;
%put &DorsHHFPath;
proc import out= al_
datafile="&DorsHHFPath/al/*.csv"
dbms=CSV replace ;
getnames=no;
datarow=3;
run;
proc import out= ga
datafile="&DorsHHFPath/ga/*.csv"
dbms=CSV replace ;
getnames=no;
datarow=3;
run;
The results are two datasets by state with the following:
var1 var2 var3
State Company Date
Al MyCompany 1/23/18
Al MyComapny 1/31/18
A similar dataset for GA. I do a separate proc import for each state (15 in all)
1.I have to use a rename for all of the vars (ie rename var1 = State)
2. In addition, Date imports as a character. Can I define it as a date9. in the initial proc import statement? Also is there a way to define the other vars based on the names directly under it (ie var2 = company)
3. In each row, the state will repeat itself depending on the number of entries for that state. Is there a way to only bring in data and say delete the row if var1(state) does not equal the state I choose (ie AL)?
1. ok, not a question here.
2. Use a data step to import the data rather than PROC IMPORT, then you can control the variable names, lengths and types. First figure it out for one and then you can make a macro. You can get the data step code from the log and change it to what you need manually first.
3. Sure, just add an IF statement to your data step code.
Untested, but since you've clearly been working on this for a while this may help you get started:
%macro import_data_states(state=);
data STATE_&state.;
infile "&dorshhfpath./&state./*.csv" dsd truncover;
input ..... ;
if state = "&state";
run;
%mend;
data _null_;
set sashelp.states; *not sure of which data set this is because I don't have maps portion installed;
str = catt('%import_data_states(state=', stateName, ');');
call execute(str);
run;
%*combine after if desired;
data All_States;
set state_: indsname=source;
dsn=source;
run;
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.