BookmarkSubscribeRSS Feed
uvaraj
Calcite | Level 5

I am trying to red the dataset in SAS and write it to a file as HTML content ,to open it in xls format.

When i try to execute the code at line "put "<TD class="xl13cAlign" x:num='&v7'>&v7</TD>";" it giving error stating " Statement is not valid or used out of proper order." if i remove the macro call or remove the proc sql which i do to read the data from dataset it is working fine. any idea what is the issue?.

Pease suggest.

%macro getOrders(dataSetName,x,Y,I);

proc sql;

create table return  as  (

select orders from

&dataSetName

where bi =%unquote(%str((%'&B%'))) and iss_yr=%unquote(%str((%'&Y%')))  and iss_no=%unquote(%str((%'&I%')))

);

run;

quit;

       

                  %let id1=%sysfunc(open(return));

                %let NObs1=%sysfunc(attrn(&id1,NOBS));

               

                %syscall set(id1);

                %do i1=1 %to &NObs1;

                                %let rc1=%sysfunc(fetchobs(&id1,&i1));

                                %let v7 = %NRBQUOTE(&orders);

                                put "<TD class="xl13cAlign" x:num='&v7'>&v7</TD>";

                              

                %end;

%mend getOrders;

                %macro excelPrintValues(dataSetName);

                data _null_;

                file "d:\twr\work\rpt207_report_&id._1.xls";

                put '<html xmlns:o="urn:schemas-microsoft-com:office:office"';

                put 'xmlns:x="urn:schemas-microsoft-com:office:excel"';

                put 'xmlns="http://www.w3.org/TR/REC-html40">';

                put '<head>';

                %let id=%sysfunc(open(&dataSetName));

                %let NObs=%sysfunc(attrn(&id,NOBS));

               

                %syscall set(id);

                %do i=1 %to &NObs;

                                %let rc=%sysfunc(fetchobs(&id,&i));

                                %let v1 = %NRBQUOTE(&B);

                                %let v2 = %NRBQUOTE(&T);

                                %let v3= %NRBQUOTE(&F);

                                 %let v13 = %NRBQUOTE(&Y);  

                                %let v4= %NRBQUOTE(&I);                                        

                                %let v5 = %NRBQUOTE(&o);                   

                                %let v6 = %NRBQUOTE(&o);

                              

                           

                          

                            put "<tr>";

                            put "<TD class="xl13cAlign" x:num='&v1'>&v1</TD>";

                            put "<TD class="xl13cAlign" >&v2</TD>";

                            put "<TD class="xl13cAlign" >&v3</TD>";

                            put "<TD class="xl13cAlign" x:num='&v13'>&v13</TD>";

                            put "<TD class="xl13cAlign" x:num='&v4'>&v4</TD>";

                            put "<TD class="xl13cAlign" x:num='&v5'>&v5</TD>";

                            put "<TD class="xl13cAlign" x:num='&v6'>&v6</TD>";

                          

                            getOrders(order_details,&B,&Y,&I);

                          

                          

                      

                            put "</tr>";

                          

             

                %end;

                %let id=sysfunc(close(&id));

%mend excelPrintValues;

2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12

The first PUT statement has to be inside a DATA step.  You put it between the end of the PROC SQL and the beginning of the DATA _NULL_.

mimi
Calcite | Level 5

I think you need %put

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1677 views
  • 0 likes
  • 3 in conversation