Desktop productivity for business analysts and programmers

SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

I am bringing in the modified date from the UNIX file system and the date populates fine as a variable.  When I tried to convert the text version of the variable (moddt2) to a macro, something goes wrong and the date is stored as '20170209' instead of '20170118.'  Can you tell me how I can get the macro facility to interpret the text correctly?


Accepted Solutions
Solution
‎04-04-2017 08:32 AM
Occasional Contributor
Posts: 6

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

I ended up using the code below to create the macro, which read the information in correctly.

 

proc sql;

select distinct max(moddt2)

into :moddt3

from dssinf1;

%put Replacement Date =&moddt3.;

View solution in original post


All Replies
Grand Advisor
Posts: 17,332

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

When you say Unix File System do you mean via a pipe or ls command? Or FINFO?

 

Anyways, it may be easier to use the MDY() function instead to create the date rather than anydtdte input format. 

I suspect that may help with some of the issues you're having.

 

moddt=mdy(input(mon, best12.), input(day, best12.), yr1);
format moddt date9.;

PS In the future please paste the code directly into the forum rather than as an attachment. 

Grand Advisor
Posts: 17,332

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

Also, 20859 in SAS is February 9, 2017.

data test;
date=20859;
format date date9.;
run;
proc print;run;

 

Occasional Contributor
Posts: 6

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

Thank you.  Yes, I used pipe.  Here is the code.  You can see from the attached picture that the date variable is 20170118.  I placed the code in the attachment with the picture because they go together and I was not able to insert the picture here.  I don't know where the interpretation of 20170209 comes from.

 

48 %put &rundate ;

20170329

49 filename _dssinf1 pipe "cd '/hasaspmt/fraud/facility/';ls -la";

50

51 data dssinf1;

52 infile _dssinf1 pad recfm=v lrecl=1024 firstobs=2;

53

54 input filename $200.;

55 listinfo=compbl(filename);

56 rwa = scan(listinfo,1,' ');

57 nm = scan(listinfo,2,' ');

58 userid = scan(listinfo,3,' ');

59 dbs = scan(listinfo,4,' ');

60 size= scan(listinfo,5,' ');

61 mon= scan(listinfo,6,' ');

62 day= scan(listinfo,7,' ');

63 recnum=_n_;

64

65 yr=scan(listinfo,8,' ');

66 yr1=year(today());

67 moddt=input(catx('-',mon,day,yr1),anydtdte11.);

68 call symput('moddt',moddt);

69 format moddt yymmddn8.;

70 moddt2=put(moddt,yymmddn8.);

71 call symputx('moddt2',moddt2);

72 typ= scan(scan(listinfo,9,' '),2,.);

73 fnam = scan(listinfo,9,' ');

74 if scan(fnam,1,.) IN ('filtered_odm_dss','filtered_odm_ufe');

75

76 run;

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).

68:22 72:35 74:16

NOTE: The infile _DSSINF1 is:

Pipe command="cd '/hasaspmt/fraud/facility/';ls -la"

NOTE: 72 records were read from the infile _DSSINF1.

The minimum record length was 59.

The maximum record length was 93.

NOTE: The data set WORK.DSSINF1 has 2 observations and 16 variables.

NOTE: DATA statement used (Total process time):

real time 0.07 seconds

cpu time 0.00 seconds

 

77 %put &moddt. &moddt2.;

20859 20170209

 

Grand Advisor
Posts: 17,332

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

I see 20170328 (yesterday) and that moddt matches moddt2 in your picture so I'm not sure what I should be seeing there. It doesn't seem to match your description of what's happening. 

 

I would suggest, using PUT to output the components of the day/month to the log to make sure they're being defined properly.

 

Did you try the MDY suggestion, did that change anything? 

Occasional Contributor
Posts: 6

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

Sorry, I've been working on this a few days and I made the correction manually yesterday, but I'll need to use this process again.  The date in the variable is correct as 20170328 but the macro keeps showing as 20170209, no matter what date the variable I created it from holds.

 

moddt=input(catx('-',mon,day,yr1),anydtdte11.);

moddt2=put(moddt,yymmddn8.);

call symputx('moddt2',moddt2);

 %put &moddt. &moddt2.;

20859 20170209

 

The solution you provided using 'mdy' instead causes the variable to display as missing '.' and creates the errors below.

 

NOTE: Invalid argument to function INPUT at line 52 column 11.

WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.

 

Grand Advisor
Posts: 17,332

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

Pull out the CATX() portion and show what that looks like. 

 

Check = catx('-', mon day, yr1);

Super User
Super User
Posts: 6,326

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

[ Edited ]

If you are trying to read the output of the LS command then you need to check if your system is modern enough to allow you to add options to the LS command to have it output the DATE in a consistent format.  Otherwise the default in Unix is to use different formats to displaying the data depending on how old the file is.  It will show just the month day and year for files that are more than 6 months old and show the month day and time for files that are less than 6 months old.

 

>ls -l xx.*
-rw-rw-r-- 1 user group 695 Dec 14 22:03 xx.sas
-rw-rw-r-- 1 user group  82 Feb 27  2016 xx.tst

>ls -l --full-time xx.*
-rw-rw-r-- 1 user group 695 2016-12-14 22:03:02.629038000 -0500 xx.sas
-rw-rw-r-- 1 user group  82 2016-02-27 15:32:41.805886000 -0500 xx.tst

So if you are using the older style you will need to add logic to handle the time.

 

filename _dssinf1 pipe "ls -l xx.*" ;

data dssinf1;
  infile _dssinf1 truncover ;
  length rwa $11 nm 8 userid $32 group $32 size 8 mon day yr time $5 datetime 8;
  input rwa -- yr filename $200. ;
  if index(yr,':') then do;
    time = yr;
    year = year(today());
    if input(cats(day,mon,year),??date9.) > today() then year=year-1;
  end;
  else do ;
    time='00:00';
    year = input(yr,4.);
  end;
  datetime = input(catx(':',cats(day,mon,year),time),datetime15.) ;
  format datetime datetime20. ;
  drop mon day yr year time ;
run;

 

 

Occasional Contributor
Posts: 6

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

Thanks, Tom!  That was a problem with the year being missing for the most recent six months, but I had a work around that was effective.  I like yours also and it works except for the ls option.  I guess I have an older version.  Smiley Sad  Do you know why when I put the date into a macro, it changes?  The actual value for moddt2 is 20170330 with a date format and moddt1 is Mar302017 with a charater format.  when I use symput to put them into macros, &moddt2 is 20170209 and &moddt1 is Feb092017.

 

36 data dssinf1;

37 infile _dssinf1 pad recfm=v lrecl=1024 firstobs=2;

38

39 input filename $200.;

40 listinfo=compbl(filename);

41 rwa = scan(listinfo,1,' ');

42 nm = scan(listinfo,2,' ');

43 userid = scan(listinfo,3,' ');

44 dbs = scan(listinfo,4,' ');

45 size= scan(listinfo,5,' ');

46 mon= scan(listinfo,6,' ');

47 day= scan(listinfo,7,' ');

48 yr=scan(listinfo,8,' ');recnum=_n_;

49 if index(yr,':') then do;

50 time = yr;

51 year = year(today());

52 if input(cats(day,mon,year),??date9.) > today() then year=year-1;

53 end;

54 else do ;

2 The SAS System 08:34 Thursday, March 30, 2017

55 time='00:00';

56 year = input(yr,4.);

57 end;

58

59

60 *yr1=year(today());

61 moddt=input(catx('-',mon,day,year),anydtdte11.);

62 call symput('moddt',moddt);

63 format moddt yymmddn8.;

64 moddt2=put(moddt,yymmddn8.);

65 moddt1=cats(mon,day,year);

66 call symputx('moddt1',moddt1);

67 call symputx('moddt2',moddt2);

68 typ= scan(scan(listinfo,9,' '),2,.);

69 fnam = scan(listinfo,9,' ');

70 if scan(fnam,1,.) IN ('filtered_odm_dss','filtered_odm_ufe');

71

72 run;

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).

62:22 68:35 70:16

NOTE: The infile _DSSINF1 is:

Pipe command="cd '/hasaspmt/fraud/facility/';ls -la "

NOTE: 73 records were read from the infile _DSSINF1.

The minimum record length was 59.

The maximum record length was 93.

NOTE: The data set WORK.DSSINF1 has 2 observations and 18 variables.

NOTE: DATA statement used (Total process time):

real time 0.07 seconds

cpu time 0.02 seconds

 

73 %put &moddt. &moddt1. &moddt2.;

20859 Feb092017 20170209

 

Super User
Super User
Posts: 6,326

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

Your program looks like it is working fine. 

 

Most likely the reason you are confused is that there are two observations in your SAS dataset. So the final value of the macro variable will be from the last observation.  So it might be that the first observation in your dataset would have generated that March date, but the last observation has overwritten that value with the February date's values.

 

Occasional Contributor
Posts: 6

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

Both observations display the same date.

Solution
‎04-04-2017 08:32 AM
Occasional Contributor
Posts: 6

Re: SAS EG 6.1 Macro (SAS 9.4 Grid 2.0)

I ended up using the code below to create the macro, which read the information in correctly.

 

proc sql;

select distinct max(moddt2)

into :moddt3

from dssinf1;

%put Replacement Date =&moddt3.;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 360 views
  • 7 likes
  • 3 in conversation