BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alicia5882
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
alicia5882
Fluorite | Level 6

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

11 REPLIES 11
Reeza
Super User

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. 

Reeza
Super User

Also, 20859 in SAS is February 9, 2017.

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

 

alicia5882
Fluorite | Level 6

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):(Column).

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

 

Reeza
Super User

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? 

alicia5882
Fluorite | Level 6

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.

 

Reeza
Super User

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

 

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

Tom
Super User Tom
Super User

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;

 

 

alicia5882
Fluorite | Level 6

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.  😞  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):(Column).

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

 

Tom
Super User Tom
Super User

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.

 

alicia5882
Fluorite | Level 6

Both observations display the same date.

alicia5882
Fluorite | Level 6

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.;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 11 replies
  • 1342 views
  • 7 likes
  • 3 in conversation