SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Mitchell16
Calcite | Level 5

Hello, I created the following grouping of variables:

%let practice_size= doctors, nurses, patients;

%let market=income, population, race;

%let organization=med_school, multi_market, affiliation;

 

For each of the variables listed above, I then created a new variable called check_variablename.

So I have check_doctors, check_nurses... check_affiliation. I am now trying to sum these check variables by the categories I created above. So I want FV_practice_size to be the sum of check_doctors, check_nurses, and check_patients. Is there a way to combine this "check" prefix with the %let statements. The following code is not functioning how I want it to.

 

 

data FV_new;

set FV_checks;

FV_practice_size=sum(of check_&practice_size.);

FV_organization=sum(of check_&organization.);

FV_market=sum(of check_&market.);

run;

 

The data looks like this:

doctors comp_doctors check_doctors nurses comp_nurses check_nurses

100     90           1             500    425         0

5 REPLIES 5
Reeza
Super User

What about this:

 

FV_market=sum(of check_:);

Mitchell16
Calcite | Level 5

That would sum all the check variables, not just three check variables in the market category.

ballardw
Super User

Since you don't want to process the variable names by CHECK then I suggest that the process that created the variables should use the appropriate prefix Practice_doctor, Practice_Nurse, Practice_Patient, Market_Income, Market_population, Market_race.

Then you could get the sums using the correct prefix.

 

Or possibly have a completely different structure such as

Roll with values of practice, market or organization

Group with the values like doctor, nurse, income, population, med_school media market

and the last variable holding a (check?) value.

Then Proc summary, means, report or tabulate would allow getting totals by the Roll variable and crossed with Group as needed.

Astounding
PROC Star

For the small number of variables you have, you might as well type out the list.  But if you are interested in extending your macro language skills (or if the lists are in reality much longer), you could take this approach:

 

  • Get rid of the commas in the values of the macro variables
  • Apply the techniques outlined in the link below to have macro language construct your lists with "check_" in front of each name

 

http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-per...

 

 

 

Ksharp
Super User
You could change it before apply it .

%let practice_size= doctors, nurses, patients;
%let check=%sysfunc(prxchange(s/(\w+)/check_$1/,-1,%bquote(&practice_size)));

%put &check ;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 30022 views
  • 3 likes
  • 5 in conversation