Trying to create new dataset using macro sas

53 views Asked by At

I have the following code:

              %macro One (Data=, City=);
                 data &data; 
                 set Dataset1;
                 Var_new=.;
                 if State = "CA" and CITYCODE = &City then output;  
                 run;
              %mend One;
              %One (Data=Bakersfield_CA,  City=12540);
              %One (Data=Chico_CA         City=17020);

I get the first dataset for Bakersfield_CA..but I get error for the second time the macro runs and I don't get any dataset called "CHico_CA".

1

There are 1 answers

3
user667489 On

You're missing a comma in your second macro call. Try

%One (Data=Bakersfield_CA,  City=12540);
%One (Data=Chico_CA,         City=17020);

In general, though, creating lots of little datasets like this is a bad idea, as it makes your code much more complicated than necessary. What are you trying to do for each city? You can probably do the same thing with your original dataset1 using by-group processing.