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

Hello ,

 

@

 

@Kurt_Bremser

 

Yes I have read several documentations about SAS macro in PDF 130-30 , 243-29 , base_macro_6997 , p071-27 .

 

I want that the macro count the number of line in a table. Why I use a macro , because to develop my SAS program in the futur I want use several time this macro , for several count in 4 or 6 tables.

 

if you want give an opinion on the SAS code , my actual code is this :

 

%macro test(var=);

count(&var);

%mend;

data work.temp;
set mybdd.mytable;
call symput(myfield);

run ;

 

Kurt_Bremser
Super User

If you had read the macro documentation, you would know how to use call symput, as it is part of the macro/data step interface.

Your code has obvious errors (I gave you the reason in my previous post), and it won't work.

Kurt_Bremser
Super User

@azertyuiop wrote:

I have tryed this macro :

 

%macro test(var=);

count(&var);

%mend;

data work.temp;
set mybdd.mytable;
call symput(myfield);

run ;

There is this message of error in logs :

 

ERROR 252-185: The SYMPUT subroutine call does not have enough arguments.

You obviously have not read the documentation. Do so to avoid such extremely simple mistakes. The documentation is there for a reason, not consulting it is a sign of foolishness.

call symput() requires TWO arguments.

Astounding
PROC Star

As you can see from all the questions here, your code is far from working.  I will give you something that works (I think), but you still have a lot of studying to do to understand why this code works and your code doesn't.  (At least I'm assuming this code works.  It might need minor tweaking, since I can't test it.)

 

%macro countrecs (dsn=);

   proc sql noprint;

   create table counts as select count(*) as record_count from &dsn;

   quit;

   data _null_;

      set counts;

      call symputx('nb_line', record_count, 'G');

   run;

%mend countrecs;

 

Then you could test it with:

 

%countrecs (dsn=database.original_table)

%put Number of lines:  &nb_line;

 

Note that I removed ID from the code.  Presumably, you would like your code to run even if the incoming data does not contain a field named ID.

ballardw
Super User

Please Provide some example input data and an example of what the final result should be. Posting non-working code does not describe the actual issue or result.

 

There are so many ways to count things in SAS and then combine that result with something else that choices need to be made based on something concrete. For instance if this is involved is displaying a result a human reads such as a report one way may be more appropriate than if the value is to be added to a data set and used for computation.

azertyuiop
Quartz | Level 8

Hello ,

 

I have used the SAS code for the macro . It's a excellent code . I can obtain the result of count in the log and in a table Man Wink

 

options compress=yes sortsize=max;

/* call database */

libname b8x meta library="my_data_base_john_doe";

/* macro to count lines */

%macro countrecs (dsn=);

   proc sql noprint;

   create table counts as 
   
   select count(*) as record_count 
   
   from &dsn;

   quit;

   data _null_;

      set counts;

      call symputx('nb_line', record_count, 'G');

   run;

%mend countrecs;

proc sql inobs=2500;

/* see several information on table */

create table consultation_abcd as select * from b8x.abcd; 
create table consultation_efgh as select * from b8x.efgh;

run; 

%countrecs (dsn=b8x.AB4D)

%put Number of lines: &nb_line;

Inside this SAS code I have had my proc sql.

 

Thanks for you help Smiley Wink

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 20 replies
  • 14334 views
  • 16 likes
  • 7 in conversation