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

Hello,

 

Its likely that I am wording my question in the subject completely wrong as I am new to SAS and don't understand all of the verbiage. However, I am trying to include a statement in my macros code that will generate a total for a number of medical codes. I will include an excerpt of the code that I have thus far. 

 

%let hcpcs=%str('36473', '36474', '36475', '36476', '36478', '36479',
'36482', '36483', '20912', '21210', '21235', '30400', '30410', '30420',
'30430', '30435', '30450', '30460', '30462', '30465', '15877', '20912',
'21210', '21235', '30400', '30410', '30420', '30430', '30435', '30450',
'30460', '30462', '30465', '30520', '36473', '36474', '36475', '36476',
'36478', '36479', '36482', '36483');

 

Is there a way that I can add another value to this string that will allow for calculations of the total of all of these codes?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

This would all be much easier if you are working with data in a data set, which I speculate you are.

 

proc sql noprint;
    select distinct quote(code) into :hcpcs separated by ',' from yourdatasetname;
quit;
%let num_codes=&sqlobs;
--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

This would all be much easier if you are working with data in a data set, which I speculate you are.

 

proc sql noprint;
    select distinct quote(code) into :hcpcs separated by ',' from yourdatasetname;
quit;
%let num_codes=&sqlobs;
--
Paige Miller
SM8
Obsidian | Level 7 SM8
Obsidian | Level 7

I am! Can you explain this a little further, please?

PaigeMiller
Diamond | Level 26

@SM8 wrote:

Can you explain this a little further, please?


If you have a data set with the codes, then this PROC SQL searches the data set for all codes contained, and puts them into the macro variable HCPCS with quotes around the codes and separated by a comma.

 

&SQLOBS is the number of (in this case) distinct codes found.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Hi @SM8 

%let hcpcs=%bquote('36473', '36474', '36475', '36476', '36478', '36479',
'36482', '36483', '20912', '21210', '21235', '30400', '30410', '30420',
'30430', '30435', '30450', '30460', '30462', '30465', '15877', '20912',
'21210', '21235', '30400', '30410', '30420', '30430', '30435', '30450',
'30460', '30462', '30465', '30520', '36473', '36474', '36475', '36476',
'36478', '36479', '36482', '36483');

%put &=hcpcs;

%let total_codes=%sysfunc(countw(&hcpcs,%str(,)));

%put &=total_codes;
PaigeMiller
Diamond | Level 26

@novinosrin wrote:

Hi @SM8 

%let hcpcs=%bquote('36473', '36474', '36475', '36476', '36478', '36479',
'36482', '36483', '20912', '21210', '21235', '30400', '30410', '30420',
'30430', '30435', '30450', '30460', '30462', '30465', '15877', '20912',
'21210', '21235', '30400', '30410', '30420', '30430', '30435', '30450',
'30460', '30462', '30465', '30520', '36473', '36474', '36475', '36476',
'36478', '36479', '36482', '36483');

%put &=hcpcs;

%let total_codes=%sysfunc(countw(&hcpcs,%str(,)));

%put &=total_codes;

Although %str() and %bquote() in this example will do the same thing, there are other situations where %str() would be the logical correct choice, and I am not able to envision a situation where %bquote() is needed in this or similar examples. In fact, the creation of &HCPCS in this example doesn't need either %str() or %bquote().

--
Paige Miller
novinosrin
Tourmaline | Level 20

"In fact, the creation of &HCPCS in this example doesn't need either %str() or %bquote() in this example." - Yes true for the reason there isn't any unbalanced quotes. So the tokenisation isn't impacted for word scanner to safely determine the literal tokens

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 671 views
  • 0 likes
  • 3 in conversation