BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aman4SAS
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ


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

8 REPLIES 8
damanaulakh88
Obsidian | Level 7

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

Aman4SAS
Obsidian | Level 7

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

DBailey
Lapis Lazuli | Level 10

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

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

Aman4SAS
Obsidian | Level 7

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

Aman4SAS
Obsidian | Level 7

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

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

DBailey
Lapis Lazuli | Level 10

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

DaylaRose
Calcite | Level 5

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

ods noproctitle;

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

Cynthia_sas
SAS Super FREQ


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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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