BookmarkSubscribeRSS Feed
rasmuslarsen
Obsidian | Level 7

 

Dear everyone

The following macro mostly works: 

It extracts the tables defined.

 

However, the "where" clause in the "proc sql" does not have any effect. So the problem is that rows are extracted which do not comply with the "where" clause. 

For example rows are returned which have ATC = "A0". 

 

Do anyone have any ideas what I am doing wrong?

 

(I have highlighted the part of the code which does seem to have the desired effect, i.e. it does not ensure that only the described ATC-codes are included)

 

 

 

 

 

 

proc sql;
select memname into :LMDB_names separated by ''
    from dictionary.tables where libname = "RAWDST"
        and memname like "LMDB%"
;quit;      
%let LMDB_len = &sqlobs;
%let LMDB_vars = pnr atc eksd;
     
%macro extract_LMDB(table_list, list_len, col_names);   
        %do i=1 %to &list_len;
        data out.%scan(&table_list, &i);
        merge out.pop (in=in_pop) pdb.%scan(&table_list, &i) (in = in_lmdb);
        by pnr;
        if in_pop = 1 & in_LMDB = 1;
        keep &col_names;
        run;     
        
        proc sql;
        create table out.%scan(&table_list, &i) as        
        select distinct
        pnr, atc,  eksd
        from out.%scan(&table_list, &i)
        
        where      
        upper(atc) like "G%" or
        upper(atc) like "D06%" or
        upper(atc) like "H02AB%" or
        upper(atc) like "G03%" or
        upper(atc) like "L04%"    
        ;quit;
        %end; 
        %mend extract_LMDB;
        
        

 

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @rasmuslarsen,


@rasmuslarsen wrote:

The following macro mostly works: 

(...)

%macro extract_LMDB(table_lidt, list_len, col_names);   
        %do i=1 to &list_len;
...

I don't believe that this macro even compiles. Whenever I forget the percent sign in the "%to" keyword (and this is my most frequent typo when writing macro code) I obtain the error messages

 

ERROR: Expected %TO not found in %DO statement.
ERROR: A dummy macro will be compiled.

 

Moreover, there seems to be a typo table_lidt in the first macro parameter (given that &table_list is used in the macro).

 

So maybe the non-compliant ATC values are from an earlier version of your code. The syntax in your WHERE clause should not cause any problem.

rasmuslarsen
Obsidian | Level 7
Thanks, you are correct. The missing '%' and misspelled word came because I had typed the program manually instead of copy-pasting, because I do not have access to copy pasting on the remote machine I am using.

Thanks, for pointing out that there should be no problem with the 'where-clause', I will look else where for the problem then 🙂


Kurt_Bremser
Super User

Run a PROC FREQ on atc to get a comprehensive list of values there. It might be that you only have values that match at least one of the conditions in the WHERE.

ballardw
Super User

Minor bit of comment but "Like "G%"  "   will also return the values from "Like "G03%" ;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 582 views
  • 1 like
  • 4 in conversation