LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 25 Apr 2007 11:19:16 +0200
Reply-To:     SAS-L List <sas-l@listserv.uga.edu>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Robert Bardos <bardos2@ANSYS.CH>
Subject:      Re: Formatting SAS dates
In-Reply-To:  <1177427024.199264.65690@u32g2000prd.googlegroups.com>
Content-Type: text/plain; charset="iso-8859-1"

Rune,

the reason for the error has already been explained ( you begin a datastep, then invoke proc format through a macro - this implicitly ends the datastep so the format statements end in "open code area" ).

I have another idea.

Maybe I'm way off track here but I think that your macro's purpose can be expressed as

substitute a date format pattern which pleases the human eye by a dateformat name that SAS understands

or in other words

if the data contains date values in form DD.MM.YYYY then use format ddmmyyp10. if DD/MM-YYYY then use format mydatefm. if DD-MM-YYYY then use format ddmmyyd10.

If so then a bunch of much simpler solutions come to mind (a format not being the last of them). But since you start with a macro variable here's my take:

%let _df = %str(DD.MM.YYYY DD/MM-YYYY DD-MM-YYYY); %let _sf = %str(ddmmyyp10. mydatefm. ddmmyyd10.);

%let _if = DD/MM-YYYY ;

%let _of = %substr(&_sf,%index(&_df,&_if),10); %put _of <&_of> ;

(where _df = data format, _sf = SAS format, _if = input format, _of = output format )

These statements can be used in open code, thereby rendering the wrapping of the whole datastep in a macro obsolete. The format statement in your datastep would then simply read as

format JournalDato AvskrDato &_of;

Hope I'm on the right track (and if not it's been a nice exercise)

Robert Bardos Ansys AG, Zurich, Switzerland

> -----Ursprüngliche Nachricht----- > Rune Runnestø > Gesendet: Dienstag, 24. April 2007 17:04 > ---------------------------------------------- lots of lines snipped .... ---------------------------------------------- > %let datoformat = DD.MM.YYYY; > *%let datoformat = DD/MM-YYYY; > *%let datoformat = DD-MM-YYYY; > > %macro create_dateformat; > proc format; > picture mydatefm (default=10) > low - high = '%d/%m-%Y' (datatype=date) ; > run; > %mend; > > %macro tp33_les_inn_sd_dok; > data tp33_sd_dok; ---------------------------------------------- lots of lines snipped .... ---------------------------------------------- > %create_dateformat; > %if "&datoformat" eq "DD.MM.YYYY" %then %do; > format > Journaldato > AvskrDato ddmmyyp10. > ; > %end; > %else %if "&datoformat" eq "DD/MM-YYYY" > %then %do; > format > Journaldato > AvskrDato mydatefm. > ; > %end; > %else %if "&datoformat" eq "DD-MM-YYYY" > %then %do; > format > Journaldato > AvskrDato ddmmyyd10. > ; > %end; > label > saksnr = "Saksnr." > doknr = "Doknr." > ; > run; > %mend tp33_les_inn_sd_dok; > > %tp33_les_inn_sd_dok; >


Back to: Top of message | Previous page | Main SAS-L page