简体   繁体   中英

SAS macro for Date

I got 2 problems regarding the SAS date using macros. To make it more complicated I am stuck with 2 specific macros that i need to use(its part of the puzzle that I try to solve).

The macro that I need to use are:

%let id=741852
%let month=January February March April May June July August September October November December

The output that I need to generate is the grade rsults for students in different dicipline. Only by changing the ID of the student the output has to be updated all by itself.

The information related to the date are only needed in the Title of my Output. my code at the moment is as follow:

Title1 "Grade for &firstname &lastname;
Tilte2 "Bithtdate : &bday;
Title3 "ID :&id"
title5 "As of &sysdate, the grades are:"

To create the bday variable I used the a function since i had the info in my data set:

CALL SYMPUTX('bday',Birth_date)

At the moment my output title 2 and 4 are as follow:

Birtdate:12556

As of 17NOV12, the grades are:

How can I use the macro &month to have both title read as follow: Birthdate: 10 Janurary 2012 and As of 15 November 2012, the grade are as follow:

(**The date may seems wrong but im working in french and days come before the month)

I tought of the %SCAN fonction but it wont udate the month if I cange the ID. plz help :)

It's not clear to me what exactly you are trying to accomplish, but here is an example of something similar. I set the locale to French to show how the date is formatted.

data a;
length firstname lastname $20;
input id firstname $ lastname $ grade birthday :date9. ;
datalines;
741852 Mary Jones 92.3 01Jan1980
654654 Chuck Berry 76.9 02Mar1983
823983 Michael Jordan 81.2 04Apr1965
;
run;

options locale=FR;

%macro printinfo(id, ds);
data _null_;
  set &ds;
  where id=&id;
  put "-----------------------------------";
  put "  Grade for: " firstname lastname;
  put "  Birthday : " birthday nldate.;
  put "  ID       : " id;
  put "  As of &sysdate., the grade is: " grade;
  put "-----------------------------------";
  put " ";
run;
%mend;

option nonotes;
%printinfo(741852,a);
%printinfo(654654,a);
option notes;

Here is the log output

-----------------------------------
  Grade for: Mary Jones
  Birthday : 01 janvier 1980
  ID       : 741852
  As of 20NOV12, the grade is: 92.3
-----------------------------------
7299   %printinfo(654654,a);
-----------------------------------
  Grade for: Chuck Berry
  Birthday : 02 mars 1983
  ID       : 654654
  As of 20NOV12, the grade is: 76.9
-----------------------------------

Without changing your other code, try these two title statements:

title2 "Birthdate: %qleft(%sysfunc(putn(&bday,worddatx.)))";
title5 "As of %qleft(%sysfunc(putn(%sysfunc(today()),worddatx.))) the grades are:";

Basically, your first macro variable bday needs to be formatted using the WORDDATX format. Also, you should use the system function TODAY() to get the current system date so you can format it as you want.

The %SYSFUNC macro function lets you execute other SAS functions, in this case PUTN and TODAY() . The %QLEFT macro function trims leading blanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM