BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Filipvdr
Pyrite | Level 9

First I select all variabel names from a data set edc_recipe. Afterwards i select the names that i want seperated by #.

Then I want to loop through the list and print for every variable an XML Tag <name> value </name> (see orange part)

Who can help me?


data colnames(keep=vname);
  set RF300l3.edc_recipe (obs=1) ;
  array n{*} _NUMERIC_ ;
  array c{*} _CHARACTER_ ;

  do i = 1 to dim(n) ;
    vname = vname(n{i}) ;
    output ;
  end ;
  do i = 1 to dim(c) ;
    vname = vname(c{i}) ;
output;
  end ;
run ;


proc sql;
select vname into:test separated by '#' from colnames where vname not in ('Date','Datim','Serial_No','NrWafers','col_ins_row_id','Facility','LotId') ;
quit;
%put &test;

Data _null_;
file outxml;
%let tab=" ";
set  output_data_keep NOBS=Lst;
if _n_=1 then do;
put '<?xml version="1.0" ?>';
put '<lot>';
end;
put '<Row>';
if type = 'RECIPE' then do;
put &tab'<Params>';
  j = 0;
   do while (scan(&test,j,'#') NE '');
  Temp = scan(&test,j,'#');
  put &tab &tab '<Temp>' vvaluex(Temp) '</Temp>';
   j= j+1;
  end;
put &tab'</Params>';
end;
put '</Row>';
if _n_ = lst then do;
put '</lot>';
end;
run;
ods xml close;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Instead of generating the list with # delimiter generate it as a comma separated list of quoted strings.

Then you can just use a DO loop to output the tagged values.

%let vlist = 'Name', 'Age', 'Sex' ;

data _null_;

  set sashelp.class ;

  do _name = &vlist ;

   _start=cats('<',_name,'>');

   _end=cats('</',_name,'>');

   _val = quote(strip(vvaluex(_name)));

   put _start _val _end @;

  end;

  put;

run;

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

I can help you with the first part.  Why not just use something like:

proc sql noprint;

  select name into:test

    separated by '#'

      from dictionary.columns

        where libname="RF300L3"

         and memname="EDC_RECIPE"

         and name not in ('Date','Datim','Serial_No',

         'NrWafers','col_ins_row_id','Facility','LotId')

  ;

quit;

As for the second part, you use the file statement, but never associated it with a file name.  Was that intentional.  Then, at the end, you close ods xml, but never opened it.  Aren't you just trying to write a text file with an xml extension?

FriedEgg
SAS Employee

filename tmp temp;

ods xml file=tmp;

/* using ods will add some tags you may not want by default, I do not know of options to remove these tags but it doesn't mean they don't exist, possibly using proc template... */

proc print data=sashelp.class; run;

ods xml close;

Reference materials concerning the SAS XML Libname Engine:

http://support.sas.com/rnd/base/xmlengine/index.html

art297
Opal | Level 21

You haven't responded to my earlier questions, but I just noticed something else that you will have to change. Within the same datastep you use %let to assign a value to a macro variable and then try to use that macro variable within the same datastep.  That won't work!  You will have to move the %let statement outside of the datastep.

Peter_C
Rhodochrosite | Level 12

Filip


without the data step specifying the tags, you might achieve what you need with the XML libname engine.

Have a look at http://support.sas.com/documentation/cdl/en/engxml/63177/HTML/default/p0c5z18meh4ilzn1cw71t8waayjq.h... for SAS9.3 XML Guide or http://support.sas.com/documentation/cdl/en/engxml/62845/HTML/default/a002592584.htm for exporting to XML in SAS9.2

peterC

Tom
Super User Tom
Super User

Instead of generating the list with # delimiter generate it as a comma separated list of quoted strings.

Then you can just use a DO loop to output the tagged values.

%let vlist = 'Name', 'Age', 'Sex' ;

data _null_;

  set sashelp.class ;

  do _name = &vlist ;

   _start=cats('<',_name,'>');

   _end=cats('</',_name,'>');

   _val = quote(strip(vvaluex(_name)));

   put _start _val _end @;

  end;

  put;

run;

Filipvdr
Pyrite | Level 9

@Art: I didnt post all my code. My XML is generated fine, I just have a problem with the orange part I want to solve.

@FriedEgg: I want really specific XML which i think can not be generated by a proc print or something else.

@Peter C.: I work with 9.1.3 here. At other project I worked indeed with XML Libname engine, but not here because i really need specific XML

@Tom: your reply is a possible answer to my question, i'm going to try it out now..

EDIT: Tom, I created my own VLIST:

'ProcessPlan','MainTool','user_id','Wafers_1','RecipeName_1','RecipeValue_1','RecipeName_2','Recip

eValue_2','RecipeName_3','RecipeValue_3','RecipeName_4','RecipeValue_4','RecipeRptName_1','RecipeR

ptValue_1','RecipeRptName_2','RecipeRptValue_2','RecipeRptName_3','RecipeRptValue_3','RecipeRptNam

e_4','RecipeRptValue_4','RecipeRptName_5','RecipeRptValue_5','StepServices_1','StepServices_2','St

epServices_3','StepServices_4','StepServices_5','col_ins_id','sstrMainStep','sstrCycleTimeExpected

','sstrReleaseStatus','RecipeParameters_1','RecipeParameters_2','RecipeParameters_3','RecipeParame

ters_4'

When i want to loop through the list it seems to cut these long parameternames somehow, any idea what this could be?

Variable like ProcessPlan, Maintool, User all goes ok till Recipename_1..

EDIT: Solution: Adding a format for _name

Thanks Tom!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1124 views
  • 0 likes
  • 5 in conversation