Help using Base SAS procedures

Simple CAT and SYSFUNC question

Accepted Solution Solved
Reply
Occasional Contributor Vic
Occasional Contributor
Posts: 7
Accepted Solution

Simple CAT and SYSFUNC question

Hi,

 

strange thing happens when I try the following:

%let DATE  = %sysfunc(intnx(day,%sysfunc(TODAY()),-1),yymmddd10.); run;

 

it works fine and shows as result: 2017-03-18 (as today is the 19th, and yesterday was the 18th, so it's okay).

 

But, when you try:

%let test = %sysfunc(cat(Keep Attention ,&datum)); %put &test;

 

you will see that the result is not Keep Attention 2017-03-18, but it's like  Keep Attention1988 which seems very strange to me.

 

Anyone any idea how I can concate the string "2017-03-18" or any similar to an string? The other date formats work fine, but that's not the point.

 

Regards, Vic


Accepted Solutions
Solution
‎03-19-2017 02:16 PM
Occasional Contributor Vic
Occasional Contributor
Posts: 7

Re: Simple CAT and SYSFUNC question

okay, wow, it works. I will try to embed it into a macro, but I don't see that it won't be the right solution. I very think your're right.

 

It will be something like this at the end:

 

%let TEST = MIS 1234 - P9 EXECUTIVE REPORT Export &&DATE&; 

 

 

within a macro but I will try tomorrow (as it is late now here in Germany Smiley Happy).

 

Regards, Vic

View solution in original post


All Replies
Super User
Posts: 5,074

Re: Simple CAT and SYSFUNC question

[ Edited ]

It doesn't seem too strange that the combination of %SYSFUNC and CAT might strip the elements being concatenated.  1988 is indeed strange.  I could imagine getting 1996 if that combination of %SYSUNC and CAT were to actually perform the subtraction (2017 minus 3 minus 18).  At any rate, macro language is built to concatenate character strings without functions.  Try:

 

%let test = Keep Attention &datum;

 

That should handle the problem nicely.

Occasional Contributor Vic
Occasional Contributor
Posts: 7

Re: Simple CAT and SYSFUNC question

Hi,

 

thank you very much for answering. My point is/was that I use it within a macro as it reads multiple Excelfiles. But maybe my way is not very productive, so I will try your proposal.

 

I will report if it works Smiley Happy.

 

Regards, Vic

Solution
‎03-19-2017 02:16 PM
Occasional Contributor Vic
Occasional Contributor
Posts: 7

Re: Simple CAT and SYSFUNC question

okay, wow, it works. I will try to embed it into a macro, but I don't see that it won't be the right solution. I very think your're right.

 

It will be something like this at the end:

 

%let TEST = MIS 1234 - P9 EXECUTIVE REPORT Export &&DATE&; 

 

 

within a macro but I will try tomorrow (as it is late now here in Germany Smiley Happy).

 

Regards, Vic

Valued Guide
Posts: 505

Re: Simple CAT and SYSFUNC question

I get 1996

%let DATE  = %sysfunc(intnx(day,%sysfunc(TODAY()),-1),yymmddd10.); run;
%let test = %sysfunc(cat(Keep Attention ,&date)); %put &test;

2817  %let DATE  = %sysfunc(intnx(day,%sysfunc(TODAY()),-1),yymmddd10.); run;
2818  %let test = %sysfunc(cat(Keep Attention ,&date)); %put &test;
SYMBOLGEN:  Macro variable DATE resolves to 2017-03-18
SYMBOLGEN:  Macro variable TEST resolves to Keep Attention1996

Keep Attention1996

2017 - 03 - 18 = 1996

2017 - 3 = 2015
2015 - 18 = 1996

Valued Guide
Posts: 505

Re: Simple CAT and SYSFUNC question

some solutions;

%symdel test date /nowarn;
%let DATE  = %sysfunc(intnx(day,%sysfunc(TODAY()),-1),yymmddd10.); run;
%let test = %sysfunc(cat(Keep Attention)) &date; %put &test;

Keep Attention 2017-03-18

%symdel test date tst /nowarn;
%let DATE  = %sysfunc(intnx(day,%sysfunc(TODAY()),-1),yymmddd10.); run;
%let test = %sysfunc(cat(Keep Attention,'&date')); %put &test;
%let tst=%sysfunc(compress(&test,%str('')));%put &tst;

Keep Attention 2017-03-18

or

data _null_;

  date=put(intnx('day',%sysfunc(TODAY()),-1),yymmddd10.);
  test = cat('Keep Attention' ,date);
  put test;

run;quit;

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 163 views
  • 3 likes
  • 3 in conversation