- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have the macro below to assign percentiles to macro variable.
It works, %pctvar(sashelp.cars, Horsepower, hp);
BUT the macro variables are LOCAL only within the macro. How to make them global?! Thanks,
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array p_ p_:;
do over p_;
call symputx(vname(p_),p_); /*only local, not global*/
end;
stop;
run;quit;
%put "p_5=&p_5. p_50=&p_50. p_95=&p_95.";
%mend;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First place to check should always be the documentation.
CALL SYMPUTX(macro-variable, value <, symbol-table>);
symbol-table
specifies a character constant, variable, or expression. The value of symbol-table is not case sensitive. The first non-blank character in symbol-table specifies the symbol table in which to store the macro variable. The following values are valid as the first non-blank character in symbol-table:
G
specifies that the macro variable is stored in the global symbol table, even if the local symbol table exists.
L
specifies that the macro variable is stored in the most local symbol table that exists, which will be the global symbol table, if used outside a macro.
F
specifies that if the macro variable exists in any symbol table, CALL SYMPUTX uses the version in the most local symbol table in which it exists. If the macro variable does not exist, CALL SYMPUTX stores the variable in the most local symbol table.
Note: If you omit symbol-table, leave it blank or use any other symbol other than G, L, or F. CALL SYMPUTX stores the macro variable in the same symbol table as does the CALL SYMPUT routine.
call symputx(vname(p_), p_, 'G' );
@hellohere wrote:
I have the macro below to assign percentiles to macro variable.
It works, %pctvar(sashelp.cars, Horsepower, hp);
BUT the macro variables are LOCAL only within the macro. How to make them global?! Thanks,
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array p_ p_:;
do over p_;
call symputx(vname(p_),p_); /*only local, not global*/
end;
stop;
run;quit;
%put "p_5=&p_5. p_50=&p_50. p_95=&p_95.";
%mend;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First place to check should always be the documentation.
CALL SYMPUTX(macro-variable, value <, symbol-table>);
symbol-table
specifies a character constant, variable, or expression. The value of symbol-table is not case sensitive. The first non-blank character in symbol-table specifies the symbol table in which to store the macro variable. The following values are valid as the first non-blank character in symbol-table:
G
specifies that the macro variable is stored in the global symbol table, even if the local symbol table exists.
L
specifies that the macro variable is stored in the most local symbol table that exists, which will be the global symbol table, if used outside a macro.
F
specifies that if the macro variable exists in any symbol table, CALL SYMPUTX uses the version in the most local symbol table in which it exists. If the macro variable does not exist, CALL SYMPUTX stores the variable in the most local symbol table.
Note: If you omit symbol-table, leave it blank or use any other symbol other than G, L, or F. CALL SYMPUTX stores the macro variable in the same symbol table as does the CALL SYMPUT routine.
call symputx(vname(p_), p_, 'G' );
@hellohere wrote:
I have the macro below to assign percentiles to macro variable.
It works, %pctvar(sashelp.cars, Horsepower, hp);
BUT the macro variables are LOCAL only within the macro. How to make them global?! Thanks,
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array p_ p_:;
do over p_;
call symputx(vname(p_),p_); /*only local, not global*/
end;
stop;
run;quit;
%put "p_5=&p_5. p_50=&p_50. p_95=&p_95.";
%mend;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Reeza:
How to do Proc Univariate with one BY Var here?!
Say byvar has value 1,2,3,4, and to systematically save varx(one numeric) percentile cut into macro variables
p_by_1_varx_10/20/30/....
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And if you're looking to bin variables by percentiles, PROC RANK is a better option IMO.