BookmarkSubscribeRSS Feed
Bruceb
Calcite | Level 5

Hello there Folks.

First time using this Forum here.

 

I'll try to be conscise regarding my problem.

 

Datasets types - 20 climate model projections for temp max and min, rain, wind and radiation = 100 csv 

 

Problem - Import and managing this dataset into SAS

 

Question - Well, I'd like to learn how I can optimize this process of importing of these 20 climate model outputs for each of my 5 variables.

For example, regarding the PROC IMPORT. How I can use Macros or Loop or Do statement in order to with one command, import and create all the files? For each variable, I'd like to run my macros and perform 20 importations.

 

After this, if I want to do a operation (using Data statement), like creating a variable to distingh the different datasets I've created, I can do by a loop right? Example below. How is possible to optimize this process, in order to avoid a complicated and long script?


 

Data model1_precipitation;

  set model1_precipitation;

  model_number=1;

run;

 

Any tips regarding this problem is really appreciate. 

Thanks!

1 REPLY 1
ballardw
Super User

If dealing with multiple data files of similar layout especialy in a text format such as CSV a data step is likely to best in the long run. One reason would be that the code is more reuseable when you do the next set of runs. Also proc import, depending on the values may generate data sets with one or more variables as character in from one source file and numeric from another. The data step allows you to specify.

 

There are methods that allow reading multiple data files using wildcards and then having the name of the input file available as a variable in the data set.

We could use more information to provide a more specific response. Such as do the model projections have column headers? Naming convention?

 

If your data doesn't have column headers you could have code that starts as simply as

filename source "c:\path\*.csv"; /* reads all csv extension files in the folder identified by path*/

 

data raw;

   infile source <various options> filename=Source;

   input maxtemp mintemp precip wind radiation;

   length InputFileName $ 200;

   InputFileName=source;

run;

 

I recommend label and format assignments.

 

If it seems that you have a separate file for each variable then we have other bits to straighten out (such as who writes there models that way) to align your data.

You do need to provide some more examples of what you actually have.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1740 views
  • 0 likes
  • 2 in conversation