Hi Everyone,
I want to initialize some variables of my datasets;
what i do is to create a macro variable contains the variable to initialize;
macro variable is like this var1=.; var 2=""; ...etc.
In a data step i want to include this macro variable by &mv.; to initialize this variables after a set statement, but put this error :"ERROR 180-322: Statement is not valid or it is used out of proper order."
So if sameone know how to do it !
Thanks.
Hello,
As @RW9 said, you don't need macros to initialize some variables in a dataset.
data test;
infile datalines;
input x1 X2 X3 $;
cards;
1 2 3
4 5 6
7 8 9
run;
data inits;
set test;
/* create a new column */
attrib x4 format=4. informat=4.;
/* Reinitialize x2 - x3 */
if _N_=2 then call missing(of x2--x3);
run;
Post code and log. Use the proper sub-windows ({i} and "little running man") for this.
data varexclu1; set varexclu; if type eq "num" then varE = cat(compress(name)," =;"); else varE = cat(compress(name),' =" " ;'); run; proc sql noprint; select varE into :vE separated by ' ' from varexclu1; quit; %put "&vE."; data in; set out ; num = 643; STAT = 6; &vE.; run;
If you use the call missing() subroutine in your created statements, you do not need to distinguish between character and numeric.
Otherwise, use a dot to set numerics to missing. X=; won't work.
I would say your hitting Learn SAS 01 Problem, lack of understanding what Macro is and how it relates to Base SAS. Base SAS is the programming language, it uses data, does manipulations etc. Macro is not for this, it is purely a find replace/text generation utility. Creation of variables should be done in Base SAS, within a datastep. Not doing this will result in errors. In all cases, macro is not needed, get code working, then if you see some repeating code, then it is the time to look at macro. Without further information I cannot suggest. Follow the guidance below Post button - post test data in the form of a datastep in a code window (its the {i} above post) and post what you want out.
Give a valid scenario of where this would be used. Provide test data in the form of a datastep, and what the ouptut should look like. Why for instance would you want to create a whole set of empty varaibles - thats just a waste of disc space. If you need to create something which matches an output specs, then create a template dataset:
proc sql; create DS_TEMPLATE (VAR1 char(200), VAR2 num); quit;
Then set that with your data:
data want; set ds_template have; run;
This will mean all variables in your template are in the output, blank where not present.
Hello,
As @RW9 said, you don't need macros to initialize some variables in a dataset.
data test;
infile datalines;
input x1 X2 X3 $;
cards;
1 2 3
4 5 6
7 8 9
run;
data inits;
set test;
/* create a new column */
attrib x4 format=4. informat=4.;
/* Reinitialize x2 - x3 */
if _N_=2 then call missing(of x2--x3);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.