DATA Step, Macro, Functions and more

need help in macro.

Accepted Solution Solved
Reply
Super Contributor
Posts: 265
Accepted Solution

need help in macro.

data sales;   

   input Region $ State $ Sales :dollar8. Year  Qtr;

   datalines;

West CA 13636 1999 1

West OR 18988 1999 1

West CA 14523 1999 2

West OR 18988 1999 2

East MA 18038 1999 1

East NC 13611 1999 1

East MA 11084 1999 3

East NC 19660 1999 2

West CA 12536 1998 1

West OR 17888 1997 1

West CA 15623 1998 3

West OR 17963 1997 2

East NC 17638 1998 1

East MA 12811 1998 1

East NC 12184 1998 4

East MA 12760 1998 4

West CA 13636 1999 1

West OR 18988 2000 3

West CA 14523 2000 4

West OR 18988 1999 2

East MA 18038 1998 1

East NC 13611 1997 1

East MA 11084 1999 2

East NC 19660 2000 2

West CA 12536 1997 4

West OR 17888 2000 4

West CA 15623 1997 3

West OR 17963 2000 4

East NC 17638 2000 3

East MA 12811 1997 3

East NC 12184 1997 4

East MA 12760 2000 3

;

run;

%macro sumry(dsn,var1,var2);

proc sort data=&dsn; by year; run;

proc means data=&dsn noobs sum mean; 

by year;

class region qtr state;

var &dsn;

where year>&var1 and year<&var2;

run;

%mend;

%sumry(sales,1998,2000);

when i run this programe it runs fine. but when i use macro then its shows no obs selected.

not able to find problem. plz help

thanks


Accepted Solutions
Solution
‎01-31-2013 04:15 PM
SAS Super FREQ
Posts: 8,743

Re: need help in macro.


Hi:

  ODS NOPROCTITLE will only get rid of the procedure title "The MEANS Procedure". It will NOT get rid of the 2nd line: Analysis Variable : Sales, which was also mentioned.

  The only way to get rid of the 2nd string is to alter the table template used by PROC MEANS. However, for calculating basic statistics, either PROC TABULATE or PROC REPORT would generate the same report without the "extra" titles.

  Without getting into issues of macro processing, look at an almost equivalent approach using SASHELP.PRDSALE, comparing MEANS with TABULATE and REPORT. As you can see, ODS NOPROCTITLE does not suppress the second string.

cynthia

proc sort data=sashelp.prdsale out=prdsale;
  by year;
  where year = 1993;
run;
ods listing close;
  
ods html file='alt_to_means.html';
ods noproctitle;
  
proc means data=prdsale nonobs sum mean; 
title 'Means';
by year;
class region quarter prodtype;
var actual;
run;


proc tabulate data=prdsale;
title 'Tabulate';
by year;
class region quarter prodtype;
var actual;
table region*quarter*prodtype,
      actual*(sum mean);
run;
   
proc report data=prdsale nowd;
title 'Report';
by year;
  column region quarter prodtype actual actual=actmn;
  define region / group;
  define quarter / group;
  define prodtype / group;
  define actual / sum 'Sum';
  define actmn / mean 'Mean';
run;
 
title;
ods html close;

View solution in original post


All Replies
Frequent Contributor
Posts: 81

Re: need help in macro.

A macro definition cannot contain a CARDS statement, a DATALINES statement, a PARMCARDS statement, or data lines. Use an INFILE statement instead of it.

Super Contributor
Posts: 265

Re: need help in macro.

i m nt using datalines in macro..  i m creating macro for proc means... plz read above

Super Contributor
Posts: 578

Re: need help in macro.

When I copy and paste your code then run it, I get this the report below.  I also get a warning that "WARNING 1-322: Assuming the symbol NONOBS was misspelled as noobs."

------------------------------------------------------------ Year=1999 -------------------------------------------------------------

                                                        The MEANS Procedure

                                                     Analysis Variable : Sales

                                Region               Qtr    State                Sum            Mean

                                --------------------------------------------------------------------

                                East                   1    MA              18038.00        18038.00

                                                            NC              13611.00        13611.00

                                                       2    MA              11084.00        11084.00

                                                            NC              19660.00        19660.00

                                                       3    MA              11084.00        11084.00

                                West                   1    CA              27272.00        13636.00

                                                            OR              18988.00        18988.00

                                                       2    CA              14523.00        14523.00

                                                            OR              37976.00        18988.00

                                --------------------------------------------------------------------

Super Contributor
Posts: 265

Re: need help in macro.

thanks sir,, i thnks its prob in my software at the time of installation..

i was confused y i m nt getting result when code is write.

Thanks

Super Contributor
Posts: 265

Re: need help in macro.

sir,,, can i change change or remove both line (which i mention in BOLD) from output???

------------------------------------------------------------ Year=1999 -------------------------------------------------------------

                                                        The MEANS Procedure

                                                     Analysis Variable : Sales

                                Region               Qtr    State                Sum            Mean

                                --------------------------------------------------------------------

                                East                   1    MA              18038.00        18038.00

                                                            NC              13611.00        13611.00

                                                       2    MA              11084.00        11084.00

                                                            NC              19660.00        19660.00

                                                       3    MA              11084.00        11084.00

                                West                   1    CA              27272.00        13636.00

                                                            OR              18988.00        18988.00

                                                       2    CA              14523.00        14523.00

                                                            OR              37976.00        18988.00

                                --------------------------------------------------------------------

Super Contributor
Posts: 578

Re: need help in macro.

I think all you need to do is include a title statement in the proc means;

New Contributor
Posts: 2

Re: need help in macro.

To suppress the Proc title, code this before your Proc Means statement:

ods noproctitle;

Removing "noobs" lets the program run w/o error.

Solution
‎01-31-2013 04:15 PM
SAS Super FREQ
Posts: 8,743

Re: need help in macro.


Hi:

  ODS NOPROCTITLE will only get rid of the procedure title "The MEANS Procedure". It will NOT get rid of the 2nd line: Analysis Variable : Sales, which was also mentioned.

  The only way to get rid of the 2nd string is to alter the table template used by PROC MEANS. However, for calculating basic statistics, either PROC TABULATE or PROC REPORT would generate the same report without the "extra" titles.

  Without getting into issues of macro processing, look at an almost equivalent approach using SASHELP.PRDSALE, comparing MEANS with TABULATE and REPORT. As you can see, ODS NOPROCTITLE does not suppress the second string.

cynthia

proc sort data=sashelp.prdsale out=prdsale;
  by year;
  where year = 1993;
run;
ods listing close;
  
ods html file='alt_to_means.html';
ods noproctitle;
  
proc means data=prdsale nonobs sum mean; 
title 'Means';
by year;
class region quarter prodtype;
var actual;
run;


proc tabulate data=prdsale;
title 'Tabulate';
by year;
class region quarter prodtype;
var actual;
table region*quarter*prodtype,
      actual*(sum mean);
run;
   
proc report data=prdsale nowd;
title 'Report';
by year;
  column region quarter prodtype actual actual=actmn;
  define region / group;
  define quarter / group;
  define prodtype / group;
  define actual / sum 'Sum';
  define actmn / mean 'Mean';
run;
 
title;
ods html close;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 382 views
  • 3 likes
  • 5 in conversation