- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
hi all,
can not run this script properly on the data step.
can anyone tell me what do i miss?
%let cnt=0;
%do i = 0 %to 10 ;
%let date=%sysfunc(putn(%sysfunc(intnx(day,'12mar2021'd,%eval(&i*-1),s)),DDMMYY10.));
%put &date.;
data check;
call symputx(haha,&date.);
datalines;
%end;
Regards,
Harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First, I don't know what you want to do.
I'm not an esper, so I can't give you advice on this.
What do you see in the log when you run this code?Please check the log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There are too many problems here. The first step in writing any macro is to create code that actually works without macros and without macro variables, for two cases, for example when i=0 and i=1. You haven't done this and your code doesn't meet that criterion. If you can write such code without macros and without macro variables, then it is relatively easy to turn it into a working macro. If you can't get it to work without macros and without macro variables, then you will never get it to work with macros and with macro variables first.
So that's the first step. When we ask people to create working SAS code without macros and without macro variables, most people never do this, and ignore the request. That is not the way to learn, and that is not the way to get results. So please, take our advice. Get the code to work without macros and without macro variables as a first step, and then we can show you how to make this a macro that works.
As far as the code presented:
you don't have a macro, and %DO will not run outside of a macro. Once you fix that, there are many other problems.
For your own debugging, put the following as the first line of your code
options mprint symolgen mlogic;
then re-run the program, look at the LOG, and see if you can figure out what the problems are. Fix as many as you can, and if you get stuck, show us the CODE and the LOG. Paste the LOG as text into the Window that appears when you click on the </> icon. Do not show us the LOG any other way. But again, as I said above, if your code doesn't work without macros and without macro variables, it will never work with macros and with macro variables.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hint:
If you do not want to actually create a data set and just execute some lines of code, such as your Call Symputx, use a data _null_. Example:
data _null_;
call symputx(haha,&date.);
run;
I am not claiming the above will run, but something like that is better than creating a data set with no observations or variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Look at this:
data check;
call symputx(haha,&date.);
The first argument to SYMPUTX must be a string expression, but you supply a variable (haha) that is not defined beforehand (neither read from a file or a dataset, nor assigned a value). The data step compiler creates the variable as numeric, and it will always be missing (look for the "uninitialized" NOTE in the log). A missing numeric value is represented with a single dot, which is not valid for macro variable names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please explain what you are trying to do.
If you want to assign the value of the macro variable DATE to a new macro variable named HAHA then just use a %LET statement.
%let haha=&date;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you just want to create a dataset with date, you can do so with the following.
data check(drop=i);
do i = 0 to 10 ;
date=put(intnx('day','12mar2021'd,(i*-1),'s'),DDMMYY10.);
call symputx(cats("haha",i),date);/* for example, this statement saves all date to macro variabled haha0-10 */
output;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%do i = 0 %to 10 ;
%let date=%sysfunc(putn(%sysfunc(intnx(day,'12mar2021'd,%eval(&i*-1),s)),DDMMYY10.));
%put &date.;
%end;
Actually this script stand alone can run Smoothly and below is the log:
6 %do i = 0 %to 10 ;
7 %let date=%sysfunc(putn(%sysfunc(intnx(day,'12mar2021'd,%eval(&i*-1),s)),DDMMYY10.));
8 %put &date.;
9
10 %end;
11
12/03/2021
11/03/2021
10/03/2021
09/03/2021
08/03/2021
07/03/2021
06/03/2021
05/03/2021
04/03/2021
03/03/2021
02/03/2021
12 quit; run;
13 ODS _ALL_ CLOSE;
i just want to create a dataset for it.
is it good to use a symputx to create it
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you just want to create a dataset, there is no need to use macros or call symputx.
Use this code.
data check(drop=i);
do i = 0 to 10 ;
date=put(intnx('day','12mar2021'd,(i*-1),'s'),DDMMYY10.);
output;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Positively no need for any macro code. A simple do loop will do it:
data want;
format date ddmmyy10.;
do i = 0 to -10 by -1;
date = intnx('day','12mar2021'd,i,'s');
output;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is this
&i*-1
Just a convoluted way to write
-&i
?