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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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