DATA Step, Macro, Functions and more

SAS GETVARC

Reply
N/A
Posts: 0

SAS GETVARC

Hi,

Just wondering if anyone has a clue about what is wrong with a bit of my program. I am getting an error on the log -
SYMBOLGEN: Macro variable FIELDVALUE resolves to
SYMBOLGEN: Macro variable DSID resolves to 1
SYMBOLGEN: Macro variable VAR_LIST resolves to FUND_CODE FUND_ID LONG_NAME
SYMBOLGEN: Macro variable DSID resolves to 1
WARNING: Argument 2 to function GETVARC referenced by the %SYSFUNC or %QSYSFUNC macro function
is out of range.

What I'm trying to do is read and output content of a dataset to an external file.

%macro json;
%let dsid=%sysfunc(open(work.fundinfo));
%if &dsid ne 0 %then
%do;
%do %while(%sysfunc(fetch(&dsid)) = 0);
%let number_of_vars = %sysfunc(countw(&var_list));
put fund_code;
%let fieldvalue= %sysfunc(getvarc(&dsid, 1));
put "&fieldvalue";
%end;
%let rc=%sysfunc(close(&dsid));
%end; /* End do - if */
%mend;

The problem seems to be happening to the first of the three column of the dataset. If I change the getvarc to look for column 2, it works fine. Column 1 is a number type and columns 2 & 3 are text - it shouldnt make a difference.

Can anyone help? Thanks.
Super Contributor
Super Contributor
Posts: 3,174

Re: SAS GETVARC

Obviously it does make a difference with SAS handling CHARACTER and NUMERIC variables differently. Did a search at the SAS support website http://support.sas.com/ and this DOC gem reference comes up.

Do you really need to have a mixture of macro and DATA step for your application processing?


Scott Barry
SBBWorks, Inc.

SAS 9.2 LANGUAGE REFERENCE

http://support.sas.com/documentation/cdl/en/sclref/59578/HTML/default/a000144252.htm
N/A
Posts: 0

Re: SAS GETVARC

I think so...

What i'm doing is reading a dataset using the open through the DDV and then trying to output to a text file using a dummy dataset (file out). The reason I need to output to a file is what I am trying to do is read in the contents of the dataset and output it in a special syntax.. kind of like xml. with the tags as the colum names and the content as the contents of the tags.
Super Contributor
Posts: 260

Re: SAS GETVARC

I think you would also achieve that using a simple Data step, with arrays, FILE and PUT statements, and VNAME (or VLABEL) function to retrieve the current variable name or label.
In fact, this is how I create XML files, if it is for one-shot use. If not, I'd rather create a custom markup ODS destination using the Template procedure.

Olivier
Super Contributor
Super Contributor
Posts: 3,174

Re: SAS GETVARC

Have a look at the SAS support website http://support.sas.com/ and search for ODS MARKUP TAGSET XML for your keywords. Or, as Olivier mentioned, a simple DATA step process to an external file would be more efficient.

Scott Barry
SBBWorks, Inc.

http://www2.sas.com/proceedings/sugi27/p134-27.pdf
SAS Super FREQ
Posts: 8,743

Re: SAS GETVARC

Hi:
That is pretty much a description of what the SAS XML Libname Engine does. For example:
[pre]
libname simple xml 'c:\temp\dataout.xml';

data simple.classout;
set sashelp.class;
run;
[/pre]

gives you data like this:
[pre]
<CLASSOUT>
<Name> Alfred </Name>
<Sex> M </Sex>
<Age> 14 </Age>
<Height> 69 </Height>
<Weight> 112.5 </Weight>
</CLASSOUT>
<CLASSOUT>
<Name> Alice </Name>
<Sex> F </Sex>
<Age> 13 </Age>
<Height> 56.5 </Height>
<Weight> 84 </Weight>
</CLASSOUT>
[/pre]

...complete with XML processing instruction and root tag at the top of the file. Otherwise, I agree with Scott and Olivier-- macro is probably overkill for this until you have the program working for ONE dataset -- then you can make it work for more than one by adding macro coding. But the bulk of the work can be done by either SXLE or ODS MARKUP. At this point, however, unless you want the default XML for an XML report, I'd recommend sticking with the Libname Engine.

cynthia
Ask a Question
Discussion stats
  • 5 replies
  • 473 views
  • 0 likes
  • 4 in conversation