BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

%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 REPLY 1
Reeza
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1217 views
  • 0 likes
  • 2 in conversation