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

I'm trying to create a macro for datetime.  I have the following codes, but I'm getting an error asking for the format.

data DateVariables;
RunDt = put("&sysdate9"d,date9.);
call symputx('RunDt',RunDt);
StartDt = put(intnx('month',today(),-1,'Beg'),date9.);
call symputx('StartDt',StartDt);
EndDt = put(intnx('month', today(),-1,'End'),date9.);
call symputx('EndDt',EndDt);
PaidFrom = put (intnx('month',today(),-1,'Beg'),0,0,0,),datetime23.2);
call symputx('PaidFrom',PaidFrom);
PaidThru = put (intnx('month',today(),-1,'Beg'),0,0,0,),datetime23.2);
call symputx('PaidThru',PaidThru);
run;


%put &RunDt;
%put &StartDt;
%put &EndDt;
%put &PaidFrom;
%put &PaidThru;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You have an unnecessary comma after 0,0,0 

 

It should be

 

PaidFrom = put (dhms(intnx('month',today(),-1,'Beg'),0,0,0),datetime23.2);

 

 

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@AMChilders wrote:

I'm trying to create a macro for datetime.  I have the following codes, but I'm getting an error asking for the format.


Show us the LOG for this code (we need to see all of the log for this code, 100% of it, do not select parts of the log to show us and not show us other parts). Also, please preserve the formatting of the log by copying it as text and pasting it into the window that appears when you click on the </> icon — DO NOT SKIP THIS STEP.

--
Paige Miller
AMChilders
Calcite | Level 5

Added original code and log below.

 

Original Code:

data DateVariables;
RunDt = put("&sysdate9"d,date9.);
call symputx('RunDt',RunDt);
StartDt = put(intnx('month',today(),-1,'Beg'),date9.);
call symputx('StartDt',StartDt);
EndDt = put(intnx('month', today(),-1,'End'),date9.);
call symputx('EndDt',EndDt);
PaidFrom = put (dhmd(intnx('month',today(),-1,'Beg'),0,0,0,),datetime23.2);
call symputx('PaidFrom',PaidFrom);
PaidThru = put (dhms(intnx('month',today(),-1,'Beg'),0,0,0,),datetime23.2);
call symputx('PaidThru',PaidThru);
run;


%put &RunDt;
%put &StartDt;
%put &EndDt;
%put &PaidFrom;
%put &PaidThru;

 

Log: 

1 The SAS System 09:00 Monday, May 17, 2021

1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='COVID Data DSS PT';
4 %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5 %LET _CLIENTPROJECTPATH='';
6 %LET _CLIENTPROJECTPATHHOST='';
7 %LET _CLIENTPROJECTNAME='';
8 %LET _SASPROGRAMFILE='/sasdata/medad/Cyclops/Ops/COVID Data DSS PT.sas';
9 %LET _SASPROGRAMFILEHOST='whiskey1';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=PNG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
14 FILENAME EGSR TEMP;
15 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16 STYLE=HtmlBlue
17 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
18 NOGTITLE
19 NOGFOOTNOTE
20 GPATH=&sasworklocation
21 ENCODING=UTF8
22 options(rolap="on")
23 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24
25 GOPTIONS ACCESSIBLE;
26 data DateVariables;
27 RunDt = put("&sysdate9"d,date9.);
28 call symputx('RunDt',RunDt);
29 StartDt = put(intnx('month',today(),-1,'Beg'),date9.);
30 call symputx('StartDt',StartDt);
31 EndDt = put(intnx('month', today(),-1,'End'),date9.);
32 call symputx('EndDt',EndDt);
33 PaidFrom = put (dhmd(intnx('month',today(),-1,'Beg'),0,0,0,),datetime23.2);
____
68
ERROR 68-185: The function DHMD is unknown, or cannot be accessed.

34 call symputx('PaidFrom',PaidFrom);
35 PaidThru = put (dhms(intnx('month',today(),-1,'Beg'),0,0,0,),datetime23.2);
_
159
ERROR 159-185: Null parameters for DHMS are invalid.

36 call symputx('PaidThru',PaidThru);
37 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DATEVARIABLES may be incomplete. When this step was stopped there were 0 observations and 5 variables.
WARNING: Data set WORK.DATEVARIABLES was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
user cpu time 0.00 seconds
system cpu time 0.01 seconds
memory 551.40k
OS Memory 21156.00k
Timestamp 05/17/2021 09:55:28 AM
Step Count 20 Switch Count 0
2 The SAS System 09:00 Monday, May 17, 2021

Page Faults 4
Page Reclaims 96
Page Swaps 0
Voluntary Context Switches 7
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0

38
39
40 %put &RunDt;
17MAY2021
41 %put &StartDt;
01APR2021
42 %put &EndDt;
30APR2021
43 %put &PaidFrom;
01JAN1960:06:12:51.00
44 %put &PaidThru;
01JAN1960:06:12:51.00
45
46
47 GOPTIONS NOACCESSIBLE;
48 %LET _CLIENTTASKLABEL=;
49 %LET _CLIENTPROCESSFLOWNAME=;
50 %LET _CLIENTPROJECTPATH=;
51 %LET _CLIENTPROJECTPATHHOST=;
52 %LET _CLIENTPROJECTNAME=;
53 %LET _SASPROGRAMFILE=;
54 %LET _SASPROGRAMFILEHOST=;
55
56 ;*';*";*/;quit;run;
57 ODS _ALL_ CLOSE;
58
59
60 QUIT; RUN;
61

PaigeMiller
Diamond | Level 26

Could you please perform the part of my instructions that indicates how to preserve the formatting of the log? This makes it much more readable, and I asked you not to skip this step.

--
Paige Miller
AMChilders
Calcite | Level 5
1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='COVID Data DSS PT';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='/sasdata/medad/Cyclops/Ops/COVID Data DSS PT.sas';
9          %LET _SASPROGRAMFILEHOST='whiskey1';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HtmlBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         data DateVariables;
27         	RunDt	= put("&sysdate9"d,date9.);
28         		call symputx('RunDt',RunDt);
29         	StartDt = put(intnx('month',today(),-1,'Beg'),date9.);
30         		call symputx('StartDt',StartDt);
31         	EndDt = put(intnx('month', today(),-1,'End'),date9.);
32         		call symputx('EndDt',EndDt);
33         	PaidFrom = put (dhms(intnx('month',today(),-1,'Beg'),0,0,0,),datetime23.2);
                                                                       _
                                                                       159
ERROR 159-185: Null parameters for DHMS are invalid.

34         		call symputx('PaidFrom',PaidFrom);
35         	PaidThru = put (dhms(intnx('month',today(),-1,'Beg'),0,0,0,),datetime23.2);
                                                                       _
                                                                       159
ERROR 159-185: Null parameters for DHMS are invalid.

36         		call symputx('PaidThru',PaidThru);
37         run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DATEVARIABLES may be incomplete.  When this step was stopped there were 0 observations and 5 variables.
WARNING: Data set WORK.DATEVARIABLES was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              379.03k
      OS Memory           21156.00k
      Timestamp           05/17/2021 10:03:34 AM
      Step Count                        23  Switch Count  0
2                                                          The SAS System                                 09:00 Monday, May 17, 2021

      Page Faults                       0
      Page Reclaims                     18
      Page Swaps                        0
      Voluntary Context Switches        4
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

38         
39         
40         %put &RunDt;
17MAY2021
41         %put &StartDt;
01APR2021
42         %put &EndDt;
30APR2021
43         %put &PaidFrom;
01JAN1960:06:12:51.00
44         %put &PaidThru;
01JAN1960:06:12:51.00
45         
46         GOPTIONS NOACCESSIBLE;
47         %LET _CLIENTTASKLABEL=;
48         %LET _CLIENTPROCESSFLOWNAME=;
49         %LET _CLIENTPROJECTPATH=;
50         %LET _CLIENTPROJECTPATHHOST=;
51         %LET _CLIENTPROJECTNAME=;
52         %LET _SASPROGRAMFILE=;
53         %LET _SASPROGRAMFILEHOST=;
54         
55         ;*';*";*/;quit;run;
56         ODS _ALL_ CLOSE;
57         
58         
59         QUIT; RUN;
60         
PaigeMiller
Diamond | Level 26

You have an unnecessary comma after 0,0,0 

 

It should be

 

PaidFrom = put (dhms(intnx('month',today(),-1,'Beg'),0,0,0),datetime23.2);

 

 

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1471 views
  • 0 likes
  • 2 in conversation