BookmarkSubscribeRSS Feed
RMP
SAS Employee RMP
SAS Employee

Hi folks,

I am trying to create a tagset for a specific export file. I am having some difficulties getting a 'loop' construct to work. Can someone tell me why this code works when I specifically assign the index value and why it does not work when using a variable?

   eval $loop 1;

   putlog $address_context[1];                  /* this line produces the desired output namely the first item in my array */

   putlog $address_context[$loop];           /* this line produces nothing */

Any help would be very much appreciated.

Regards

Richard

1 REPLY 1
Cynthia_sas
Diamond | Level 26

Hi:

  I didn’t use PUT/PUTLOG the way you do in your TAGSET template. It sounds like you are designing a template for use with the SAS XML Libname engine, correct? Not for use with ODS?

  Mostly, I used PUTLOG and PUT to write out  quoted “pairs”, so for example…if I had PUT I used it sort of like they show in the doc…

http://support.sas.com/documentation/cdl/en/odsug/66611/HTML/default/viewer.htm#n0luvkrmcfepfen1wmf0...      where it says that


If the variable does not have a value, then the text is not  written, and there is no output for the text or the variable. For example, for
the following PUT statement, if the variables BackGround, ForeGround, and CellPadding do not have values, then the output is <table> followed by a new line:

put '<table' 'background=' background 'foreground=' foreground 'cellpadding=' cellpadding '>' nl;

 

    So I used PUT in the same way for writing out the attribute/value pairs easily to generate custom XML. If there WAS a value for the BACKGROUND attribute, then background=cx123456 would be
written, but if there was no value for background, then no part of the text string would be written. I found some old PROC TEMPLATE code that use a similar reference to what you show. The code I
found was in a DO/DONE block, but with a SET and $col_names[$index], which, as I remember resolved just fine, but it was not using the reference in a PUT
statement in PROC TEMPLATE:

do /while $index <= $count;

            set $name  $col_names[$index] ;

            set $value $col_values[$name] ;

            trigger EmitCol ;

            eval $index $index+1;

done;

    

  So I’m not sure what is different about PUT/PUTLOG…in your example, it is puzzling how it can find a value when the 1 is hard-coded, but not when the value is set to 1 and you use the internal variable.

  I think your best resource will be working with As far as I know, the only folks who write custom tagsets are in Tech Support or folks who use the XML Mapper to generate .map files for use with the XML Libname engine.

cynthia

  

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1107 views
  • 0 likes
  • 2 in conversation