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

Hello:

 

I have the example program to create a Nn macro by proc sql.   Is there a way to create a table to list all of the Nn?  I could find the N1-N500 from 'Results' individually.  However, I would like to review the table from SAS work library.  Thanks.

 

 

data have;

informat name $80.;

input name &;

cards;

John If_True kary

John If_True Mary

John If_True kary

John If_True kary

Tom If_Not Carol

Tom If_Not Carol

Tom If_Not Carol

Joe If_True Jane

Joe If_False Jane

Joe If_False Paul

Joe If_False Jane

Paul If_False Jane

Joe If_False Jane

Joe If_False Jane

;

proc SQL;

SELECT

sum(case when find (name,'If_True')>0 and index(Name,'kary')>0 then 1 else 0 end) into: N1 FROM have;

SELECT

sum(case when find (name,'If_False')>0 and index(Name,'Paul')>0 then 1 else 0 end) into: N2 FROM have;

quit;

 

%put &n1;

%put &n2;

 

I would like the table showing the result is

N1 3

N2 2

 

or

N1  N2

3   2

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The %put function has options to list the macro variables in a current scope:

 

%put _user_;

will display ALL user defined variables

 

 

Putting much data into macro variables is often a path to madness.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Can you please show us ( a portion of) data set HAVE?


Can you please show us (a portion of) the end result you would like to have?

 

Why, if you want the end result to be a table, are you putting the values into MACRO variables? You can't easily make a table of macro variables.

 

 

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please follow the guidance at the create a new question page, just below Post.  Post example test data in the form of a datastep, what the output should look like.  Also, please refer to the other questions you have posted here - almost none of them have been marked Correct.

 

If you want a list you use into with the separated by clause, think I provided this before.  However with test data and what you want to do there is other solutions - again as I provided before.

Kurt_Bremser
Super User

If you want a list of results, store it in a dataset, not in macro variables. Datasets are WAY easier to handle.

Since what you want is just a count for certain strings, you should first create a table of said strings.

Depending on the substrings you're looking for (eg if they are always single words), the whole exercise could end up being a datastep, a proc freq and possibly a join (if you want to assign special "labels" for each string).

ballardw
Super User

The %put function has options to list the macro variables in a current scope:

 

%put _user_;

will display ALL user defined variables

 

 

Putting much data into macro variables is often a path to madness.

Reeza
Super User

See SASHELP.VMACRO table.

 

 

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
  • 5 replies
  • 394 views
  • 1 like
  • 6 in conversation