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?
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;
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;
I am! Can you explain this a little further, please?
@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.
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;
@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().
"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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.