BookmarkSubscribeRSS Feed
Quartz | Level 8
data have;
  input @1 number $char1. 
        @3 date $char10.;
1 01/01/1990
2 02/02/1992

data want;
  input @1 number best1. 
        @3 date DDMMYY10.;
  format date date9.;
1 01/01/1990
2 02/02/1992

Codes above to generate datasets 'have' and 'want'.


The following codes can be used to explicitly reassign the format of those two columns:

data target;
set have;

format temp1 best1.; temp1 = input(number,best8.); drop number; rename temp1=number;
format temp2 date9.; temp2 = input(date, ANYDTDTE10.); drop date; rename temp2=date;

However, is there a way to ask SAS to automatically reassign formats for all columns in a table?


e.g. with the Import Wizard, SAS EG can assign a default Type, Len. etc. (depending whether the column has only numbers, or date values).

Diamond | Level 26 RW9
Diamond | Level 26

Well, the problem with your methodology would be what default to apply.  Numbers could be anything from 16 to 1, include signs and decimals.  Characters can contain anything and be up to 2000 long, and dates can come in any number of formats (and could be char or number).  So the quesiton is how are you going to standardise all this?  What are your rules?  What are the error capture necessities etc.  Techinically it is possible to generate the necessary program, however you need to have all your rules in place and for them to cover every eventuality.


A more pertinent question is why do you not know what your data is like?  Why the need to change formats and such like after the event, sounds like something earlier in the process is not working, maybe your importing from Excel (as Excel is a poor data medium) and using proc import (a guessing procedure, multiplies the issues you will have with Excel).  So a solution there would be to use a robust data medium (CSV, XML etc.) and write a datastep import program to specifically import the data into the model you need.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 in conversation