This question already has answers here:
How to get current month name and year in SAS using macro
(2 answers)
Closed 2 years ago.
I want to create a sas macro global variable with current month in the format OCT i.e., only first 3 letters of current month are expected in the output in upper case. Please guide me.
220 %let cm3 = %sysfunc(putn("&sysdate"d,monname,3),$upcase3.);
221 %put NOTE: &=cm3;
NOTE: CM3=OCT
Related
This question already has answers here:
When or Why to use a "SET DEFINE OFF" in Oracle Database
(2 answers)
How to avoid variable substitution in Oracle SQL Developer
(5 answers)
Closed 1 year ago.
This is for Oracle, not MySql in case there might be a slight difference.
I am trying to get paths of this url
select regexp_substr(
'https://domain/l202108091338.csv.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAQ6R%2F20210820%2Fca-central-1%2Fs3%2Faws4_request&X-Amz-Date=20210820T223109Z&X-Amz-Expires=300&X-Amz-Signature=bd3d40250afdc751c67c58302a2ca152c7&X-Amz-SignedHeaders=host',
'[^=]+',
1,
2
) from dual;
the above command outputs
AWS4-HMAC-SHA256-Amz-Credential
but the actually value is
AWS4-HMAC-SHA256&X-Amz-Credential
How can I make the output includes &X too?
Thanks in advance for any suggestions and help.
This question already has answers here:
Regex to match Date
(7 answers)
Closed 2 years ago.
I made a google forms which i asked a date of birth like dd/mm/yyyy.
I'm looking for a RegEx that allow every date from 01/01/1900 to 31/12/2015 but refuse every date who contains this 5 years 2016, 2017, 2018, 2019, 2020.
Does someone have an idea ?
Thanks for help.
If you really only want to check dates for years 1900-2015, it suffices to code
\b(\d{1,2}/\d{1,2}/(19\d{2}|200\d|201[0-5]))\b
The \b...\b bound is less restrictive than ^...$
Because the previous answer did not specify any year bounds, they need to be added, for example, 1900…2099 (excluding 2016-2020)
\b(?!2016|2017|2018|2019|2020)(\d{1,2}/\d{1,2}/(19|20)\d{2})\b
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I have a series of dates that I am trying to separate into years, months and days. These dates are in the yyyy-mm-dd format. I'm not very familiar with RegEx, but I have tried (\dddd)\-(\dd)\-(\dd).
Any help is appreciated.
Accepted answer would also match invalid dates like 1234-56-78, or if mm & dd were in the wrong positions.
([1-2][0-9]{3})\-([0-1][0-9])\-([0-3][0-9])
Does a little more validation.
I am a new learner of sas language. I know that this is easy for you. I just want to understand how does it work using macro variables. In fact , I just need to run a sas program correctly. I have tow marco variables
&x=12,20,40,77
&y=12,45,54,78
I just need to compute the max and the min of them.So I write this code:
%let &x=12 20 40 77;
%let &y=12 45 54 78;
%put max min (&&x);
%put max min (&&y);
It shows me this error saying:
Open code statement recursion detected
I tried to find solution but it doesn't work !how resolve it please?
To get the error you received you have probably confused SAS. The code you posted generates these errors:
WARNING: Apparent symbolic reference X not resolved.
ERROR: Expecting a variable name after %LET.
1 %let &x=12 20 40 77;
2 %let &y=12 45 54 78;
WARNING: Apparent symbolic reference Y not resolved.
ERROR: Expecting a variable name after %LET.
3 %put max min (&&x);
WARNING: Apparent symbolic reference X not resolved.
max min (&x)
4 %put max min (&&y);
WARNING: Apparent symbolic reference Y not resolved.
max min (&y)
In the first statement you are trying to create a macro variable by using the value of the macro variable X as the name of the macro variable. But X was never defined so &X just resolved to &X. Since & is not a valid character to use in the name of a macro variable you end up with an invalidly formed %let statement.
If we fix the first two statements so that they generate valid %LET statements then the code runs. It is not clear what you wanted it to do but it works as SAS intended.
5 %let x=12 20 40 77;
6 %let y=12 45 54 78;
7 %put max min (&&x);
max min (12 20 40 77)
8 %put max min (&&y);
max min (12 45 54 78)
The extra & in the %put statements just make SAS have to take two passes to resolve the macro variable references. The first pass will resolve && to & and trigger the macro processor to make another pass. Then the second pass will properly resolve the resulting &x to the string 12 20 40 77.
It is best to work with numbers using SAS code and not macro code. If you want to find the max of a list of numbers using the MAX() function. Normally you can use the OF keyword in data steps when you have values separated by spaces but that only works with variable names, not literal values. So change the spaces to commas.
9 %put &=x ;
X=12 20 40 77
10 data _null_;
11 max=max(%sysfunc(translate(&x,%str(,),%str( ))));
12 put max=;
13 run;
max=77
If you really want to stay in macro language only then use %SYSFUNC() function again to call the MAX() function.
14 %put max=%sysfunc(max(%sysfunc(translate(&x,%str(,),%str( )))));
max=77
Refer to this link
I tried it around like this.
%let val1=17, 24, 35, 76;
%let val2=87, 32, 45, 6;
data _null_;
max=%sysfunc(max(&val1, &val2));
min=%sysfunc(min(&val1, &val2));
put max= min=;
run;
I hope it helps.
This question already has an answer here:
sas MACRO ampersand
(1 answer)
Closed 8 years ago.
I have a question on an exam paper which asks what is read in the SAS log
%let test=one;
%let one=two;
%let two=three;
%let three=last;
%put what displays is &&&&&test;
I was very surprised to find the answer was: two as I would have thought that this reference would fully resolve to last. SAS also agrees with the answer to be two.
Can anyone please explain how SAS arrives at the answer two as all theory notes I have read suggests that the macro processor should do the following
scan1 &&&&&test - > &&&&test ( i.e && resolves to & and tells processor to continue to scan from right to left)
scan2 &&&&test - > &&&one
scan3 &&&one - > &&two
scan4 &&two - > &three
scan5 &three - > last
Using the symbolgen option can help see what is happening in the log:
1 options symbolgen;
2 %let test=one;
3 %let one=two;
4 %let two=three;
5 %let three=last;
6
7 %put what displays is &&&&&test;
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable TEST resolves to one
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable ONE resolves to two
what displays is two
Going left to right and using brackets to show the tokens:
&&&&&test
(&&)(&&)(&test)
(&) (&) (one)
&&one
(&&)(one)
(&)(one)
&one
two