% Let statement

  • Follow


Rather new to sas and am trying to use a %let statement.

I want to make use a % let statement for 0806, so I only have to change that number once in my code. You see it 4 times used below. I don't have a macro setup in this code. 


/*join call*/
proc sql;
create table spd.acq_data_0806_2 as
(select a.*, b.*
from spd.acq_data_0806 as a
quit;

/*flag state, and add var*/
data spd.acq_data_0806_3;
set spd.acq_data_0806_2;

What all do I need to include in order use a %let statment similar to %let day=0806.
0
Reply chadmcrawford (26) 8/7/2012 1:55:11 PM

On Tuesday, August 7, 2012 8:55:11 AM UTC-5, (unknown) wrote:
> Rather new to sas and am trying to use a %let statement.
> 
> 
> 
> I want to make use a % let statement for 0806, so I only have to change that number once in my code. You see it 4 times used below. I don't have a macro setup in this code. 
> 
> 
> 
> 
> 
> /*join call*/
> 
> proc sql;
> 
> create table spd.acq_data_0806_2 as
> 
> (select a.*, b.*
> 
> from spd.acq_data_0806 as a
> 
> quit;
> 
> 
> 
> /*flag state, and add var*/
> 
> data spd.acq_data_0806_3;
> 
> set spd.acq_data_0806_2;
> 
> 
> 
> What all do I need to include in order use a %let statment similar to %let day=0806.

asssign a macro variable day to the 0806 and use &day in the rest of the code. also, check the syntax of your sql code 

%let day = 0806;
proc sql;
 create table spd.acq_data_&day_2 as
 (select a.*, b.*

from spd.acq_data_&day as a

 quit;



 /*flag state, and add var*/
data spd.acq_data_&day_3; 
set spd.acq_data_&day_2;
run;

HTH
Al
0
Reply ali6058 (166) 8/7/2012 2:42:44 PM


On Tuesday, August 7, 2012 8:55:11 AM UTC-5, (unknown) wrote:
> Rather new to sas and am trying to use a %let statement.
> 
> 
> 
> I want to make use a % let statement for 0806, so I only have to change that number once in my code. You see it 4 times used below. I don't have a macro setup in this code. 
> 
> 
> 
> 
> 
> /*join call*/
> 
> proc sql;
> 
> create table spd.acq_data_0806_2 as
> 
> (select a.*, b.*
> 
> from spd.acq_data_0806 as a
> 
> quit;
> 
> 
> 
> /*flag state, and add var*/
> 
> data spd.acq_data_0806_3;
> 
> set spd.acq_data_0806_2;
> 
> 
> 
> What all do I need to include in order use a %let statment similar to %let day=0806.

%let day = 0806;

> proc sql;
> 
> create table spd.acq_data_&day_2 as
> 
> (select a.*, b.*
> 
> from spd.acq_data_&day as a
> 
> quit;
> 
> 
> 
> /*flag state, and add var*/
> 
> data spd.acq_data_&day_3;
> 
> set spd.acq_data_&day_2;
run;

also , check you sql code for syntax errors
HTH
Al
0
Reply ali6058 (166) 8/7/2012 2:52:33 PM

On Tuesday, August 7, 2012 10:42:44 AM UTC-4, Al wrote:
> On Tuesday, August 7, 2012 8:55:11 AM UTC-5, (unknown) wrote: > Rather ne=
w to sas and am trying to use a %let statement. > > > > I want to make use =
a % let statement for 0806, so I only have to change that number once in my=
 code. You see it 4 times used below. I don't have a macro setup in this co=
de. > > > > > > /*join call*/ > > proc sql; > > create table spd.acq_data_0=
806_2 as > > (select a.*, b.* > > from spd.acq_data_0806 as a > > quit; > >=
 > > /*flag state, and add var*/ > > data spd.acq_data_0806_3; > > set spd.=
acq_data_0806_2; > > > > What all do I need to include in order use a %let =
statment similar to %let day=3D0806. asssign a macro variable day to the 08=
06 and use &day in the rest of the code. also, check the syntax of your sql=
 code %let day =3D 0806; proc sql; create table spd.acq_data_&day_2 as (sel=
ect a.*, b.* from spd.acq_data_&day as a quit; /*flag state, and add var*/ =
data spd.acq_data_&day_3; set spd.acq_data_&day_2; run; HTH Al

So %macro macro1(day);

and then put a %mend at the end of my code. is that what you are referring =
too?
0
Reply chadmcrawford (26) 8/7/2012 3:50:54 PM

On Tue, 7 Aug 2012 08:50:54 -0700 (PDT), chadmcrawford@gmail.com
wrote:

>On Tuesday, August 7, 2012 10:42:44 AM UTC-4, Al wrote:

>>On Tuesday, August 7, 2012 8:55:11 AM UTC-5, (unknown) wrote:

>>> Rather new to sas and am trying to use a %let statement.
 
>>> 
>>> I want to make use a % let statement for 0806, so I only have to change that number 
>>>once in my code. You see it 4 times used below. I don't have a macro setup in this code. 
>>> 
>>> /*join call*/
>>> 
>>> proc sql;
>>> 
>>> create table spd.acq_data_0806_2 as
>>> 
>>> (select a.*, b.*
>>> 
>>> from spd.acq_data_0806 as a
>>> 
>>> quit;
>>> 
>>> /*flag state, and add var*/
>>> 
>>> data spd.acq_data_0806_3;
>>> 
>>> set spd.acq_data_0806_2;
>>> 
>>> What all do I need to include in order use a %let statment similar to %let day=0806.

>>asssign a macro variable day to the 0806 and use &day in the rest of the code. also, check the syntax of your sql code 
>>
>>%let day = 0806;
>>proc sql;
>> create table spd.acq_data_&day_2 as
>> (select a.*, b.*
>>
>>from spd.acq_data_&day as a
>>
>> quit;
>>
>> /*flag state, and add var*/
>>data spd.acq_data_&day_3; 
>>set spd.acq_data_&day_2;
>>run;

>So %macro macro1(day);
>
>and then put a %mend at the end of my code. is that what you are referring too?

Nothing in Al's message (which somehow got mangled in your response
and is reformatted above) mentioned %macro and %mend.  Why do you
think either is needed?  It is possible to create and use macro
variables without invoking any macros.

-- 
Remove del for email
0
Reply schwarzb3978 (1358) 8/7/2012 10:33:38 PM

On Tue, 7 Aug 2012 07:42:44 -0700 (PDT), Al <ali6058@gmail.com> wrote:

>On Tuesday, August 7, 2012 8:55:11 AM UTC-5, (unknown) wrote:
>> Rather new to sas and am trying to use a %let statement.
>> 
>> 
>> 
>> I want to make use a % let statement for 0806, so I only have to change that number once in my code. You see it 4 times used below. I don't have a macro setup in this code. 
>> 
>> 
>> 
>> 
>> 
>> /*join call*/
>> 
>> proc sql;
>> 
>> create table spd.acq_data_0806_2 as
>> 
>> (select a.*, b.*
>> 
>> from spd.acq_data_0806 as a
>> 
>> quit;
>> 
>> 
>> 
>> /*flag state, and add var*/
>> 
>> data spd.acq_data_0806_3;
>> 
>> set spd.acq_data_0806_2;
>> 
>> 
>> 
>> What all do I need to include in order use a %let statment similar to %let day=0806.
>
>asssign a macro variable day to the 0806 and use &day in the rest of the code. also, check the syntax of your sql code 
>
>%let day = 0806;
>proc sql;
> create table spd.acq_data_&day_2 as

Doesn't that need to be &day._2?

> (select a.*, b.*
>
>from spd.acq_data_&day as a
>
> quit;
>
>
>
> /*flag state, and add var*/
>data spd.acq_data_&day_3; 
>set spd.acq_data_&day_2;

Also for the two above.

>run;

-- 
Remove del for email
0
Reply schwarzb3978 (1358) 8/7/2012 10:33:38 PM

5 Replies
24 Views

(page loaded in 0.1 seconds)


Reply: