Question

I'm new to SAS and I'm trying to retrieve data from a remote server.

Below is the code that I am trying to execute on the remote server:

rsubmit;
libname abc'server/sasdata'; *This is where the datasets are located;   
data all2009;
    set abc.file_2007:; 
    by index date time;
    where index in (var1) and time between '8:30:00't and '12:00:00't;
run;
endrsubmit;

Currently, I am trying to pass along the variable var1 which contains the string index that the "query" needs. var1 is evaluated on my local machine and contains the value 'abc'.

But, since var1 is evaluated locally, trying to refer to the variable on the remote server produces an error since var1 does not exist there.

If I run the code as follows (with the explicit value of 'abc') it runs fine:

...
set abc.file_2007:; 
by index date time;
where index in ('abc') and time between '8:30:00't and '12:00:00't;
...

I need to run this "query" dynamically. Is there a way to force var1 to be replaced by its actual value (ie. 'abc') before trying to execute the code enclosed in rsubmit and endrsubmit?


UPDATED: Entire Code (I left out the remote server specific ones, but I'm able to connect no problem):

LIBNAME local 'C:\...\Pulled Data\New\';
FILENAME csvfile 'C:\...\Pulled Data\New\indexes.txt';

%macro getthedata(nrows,ystart,yend); *nrows is the number of rows in the text file;

    %GLOBAL var1 var2 var3 var4;

    %do i=1 %to &nrows;
        %do m=&ystart %to &yend;

            DATA local.trow; 
               INFILE csvfile FIRSTOBS=&i OBS=&i;
               INPUT var1 $ var2 $ var3 $ var4 $;
            RUN;

            PROC PRINT DATA = local.trow;
            TITLE "Title - &i. &var1. &m";
            var var1 var2 var3 var4;
            RUN;

            proc export data=local.trow
                outfile="C:\...\Pulled Data\New\Indices_&i._&m..csv"
                dbms=csv replace;
            run;

            signon username=_prompt_;
            %syslput VAR1 = &var1;
            rsubmit;
                    libname abc'server/sasdata';    
                    data all2009;
                         set abc.file_2007:; 
                         by index date time;
                         where index in (&VAR1) and time between '8:30:00't and '12:00:00't;
                    run;
            endrsubmit;

        %end;
    %end;
%mend getthedata;

Options MPRINT;

%getthedata(1,2007,2007)

With this code, the PROC PRINT statement correctly prints a table showing the var variables and their values. The TITLE statement properly evaluates the i and m variables, but leaves the var1 off altogether.

The proc export statement creates the correct CSV file containing the expected values for each var variable.

As suggested, I tried to declare the var variables as GLOBAL, but that didn't seem to have any effect. The code still appears unable to properly pass the var1 variable to the remote server.

Again, the code works perfectly well if I replace &VAR1 with the actual string value of the variable.

The error I get is:

ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: a quoted string,
              a numeric constant, a datetime constant, a missing value.

Could it be that the WHERE clause in this case cannot accept variables?

Was it helpful?

Solution

If you put the VAR1 value in a macro variable, on/in your local machine/session you can pass that macro to the remote server using the %SYSLPUT command.

you place it between the SIGNON and RSUBMIT commands.

Signon;
%SYSLPUT VAR1=&var1;
RSubmit;

Then &VAR1 is available in your remote session. Depending on what you are passing in &VAR1, you may need some macro quoting. Post the value if you have problem with this method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top