Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making a dataset from a dataset 1

Status
Not open for further replies.

imarosel

Technical User
Jun 23, 2005
149
US
Writing my first program here. I have a csv file that I'm importing into SAS and then doing subsequent calculations to etc. Thanks to klaz2002 I know how to convert a char date to a SAS date. Now that I have my dataset made I am adding columns to it etc. I figure the best way to do this is to make a new dataset.

data work.converteddata;
set work.importedcsv;
newcolumn1 etc. etc.

run;

Is this what you would do, or would you convert the imported dataset?
 
What do you actually need to do? (ie why are you wanting to create columns?). In SAS you don't need to "create" columns to load data into them, you just refer to them and they are created for you.
The most efficient way is to add the calculations in to the datastep that reads in the CSV file...
Code:
data mydset;
  infile blah recfm=v lrecl=2056 dsd dlm=',' missover firstobs=2;

  length ...
         ...
         ;
  input ...
        ...
         ;

  new_column1 = <calculation> ;
  new_Column2 = <calculation> ;
run;
if you want to be good, you can list the new columns in the LENGTH statement to define them correctly (useful if you want to be certain of their size or numeric accuracy).
The reason that this is more efficient than adding a new datastep is that each datastep reads in every record and writes every record out. A good practice when learning is to write out the job in steps, then go back through it and see which processes can actually be grouped into fewer steps.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thanks Chris, so obvious I didn't even know.
 
No worries, it's hard getting started with a new language. SAS is very forgiving in alot of ways, so you'll often find that things are alot simpler than you'd expect. But then some times, you'll find you'll have to go all round the houses writing reams of code to do something that seems really simple. :)

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top