Hy everyone,
how can I write this expression inside of a macro,
%if stat in ('MEAN','MIN','MAX') %then format ¯ovariable 6.2;....(I know I can write three times %if stat= ' X' %then ....) but,
are the logical (in, not in, or, and) recognize inside of a macro?:
Thanks.
Michtka,
It looks like you are trying to make SAS do things that it just won't do. It looks like you are trying to process a SAS data set using macro language.
Just for the record, macro language does contain an IN operator, usually using the # character. It was introduced in 9.2, but not really working until 9.3. So you have to be running 9.3 to be able to use it.
The bigger point though is that it seems you are trying to process a SAS data set using macro language. That just won't happen. For example, a macro language statement that begins %if stat = 'MEAN' will compare four characters ("stat") to six characters ("'MEAN'") and find that they are never equal. I suspect that you have a SAS data set that contains a variable named STAT. A macro language %IF statement will only examine the value of a macro variable, never the value of a DATA step variable. A secondary issue would be that a format for a DATA step variable cannot change from one observation to the next. The format applies to the entire column of data.
If I've interpreted this wrong, and your problem is really something else, you can always add a description of your inputs and desired outputs.
Good luck.
Michtka,
It looks like you are trying to make SAS do things that it just won't do. It looks like you are trying to process a SAS data set using macro language.
Just for the record, macro language does contain an IN operator, usually using the # character. It was introduced in 9.2, but not really working until 9.3. So you have to be running 9.3 to be able to use it.
The bigger point though is that it seems you are trying to process a SAS data set using macro language. That just won't happen. For example, a macro language statement that begins %if stat = 'MEAN' will compare four characters ("stat") to six characters ("'MEAN'") and find that they are never equal. I suspect that you have a SAS data set that contains a variable named STAT. A macro language %IF statement will only examine the value of a macro variable, never the value of a DATA step variable. A secondary issue would be that a format for a DATA step variable cannot change from one observation to the next. The format applies to the entire column of data.
If I've interpreted this wrong, and your problem is really something else, you can always add a description of your inputs and desired outputs.
Good luck.
Hi:
Astounding is correct, that you cannot test data set variables in a macro program. However, using PROC REPORT, you can apply one format for one value in a report row, versus another format for a different value. For example, suppose I use PROC SUMMARY on SASHELP.SHOES to get the standard 5 statistics into a data set. Then I can format each statistic separately using CALL DEFINE in PROC REPORT. This is a REPORT (not a dataset) generated by PROC REPORT. Notice the different formats for each report row for the Sales column, but the condition for the format was based on the value of the _STAT_ column (created by PROC MEANS/SUMMARY):
Stat Sales
N 395
MIN $325.00
MAX 1,298,717.00
MEAN $85,700.17
STD 129,107.2339
Not quite what the OP originally described, but PROC REPORT does have this flexibility. Code below.
cynthia
proc summary data=sashelp.shoes;
var sales;
output out=work.statsales / autoname;
run;
proc report data=work.statsales nowd;
column _stat_ sales;
define _stat_ / display 'Stat';
define sales / display 'Sales';
compute sales;
if _stat_ = 'N' then
call define(_col_,'format','comma6.');
else if _stat_ in ('MIN', 'MEAN') then
call define(_col_,'format','dollar16.2');
else if _stat_ = 'MAX' then
call define(_col_,'format','comma16.2');
else if _stat_ = 'STD' then
call define(_col_,'format','comma20.4');
endcomp;
run;
Sounds like you want data step to reformat data differently based on value in another variable.
You will need to store this into a character variable. You can use the PUTN() function to do this.
if stat in ('MEAN','MIN','MAX') then charvar= putn(numvar,"6.2");
else if stat = 'N' then charvar=putn(numvar,6.);
else charvar='UNK STAT';
.
Sorry Guys, it was a mistake...now i understood the concept of using macrovariables with the Astounding's explanation.
Yes Tom, it was my idea.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.