Naga Vemprala
Naga Vemprala

Reputation: 728

SAS format in data step

I have a WORK dataset with more than 30 columns but only 2 columns out of them are date fields. (Start date and End date). I want the date format in the permanent dataset to be in date. and not in yymmdd10. which is the current format in work dataset. When I used the below code, the two date fields are taking first two positions. I dont want to reorder the positions and at the same time dont want to mention the format with all 30+ columns. Could someone please help me if there is any way for this?

data DLR.DEALER; 
set  work.dealer_invoices; * this dataset contains more than 30 columns; 
format start_dt end_dt date.; 
run; 

I could not find any solution for this on our site. Any help is highly appreciated than just asking me to mention all the columns in the format statement :) Thanks in advance.

Upvotes: 0

Views: 6241

Answers (1)

Joe
Joe

Reputation: 63424

Certainly the format statement shouldn't have any impact on ordering given its location.

A workaround would be to use PROC DATASETS to change the format instead of in the data step.

You also could "mention all columns" fairly easily.

proc sql;
  select name into :namelist separated by ' '
  from dictionary.columns
  where libname='WORK' and memname='DEALER_INVOICES'
  order by varnum;
quit;

then

data DLR.DEALER;
  retain &namelist;
  set work.dealer_invoices;
  format...;
run;

Upvotes: 1

Related Questions