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

I have tried using as suggested by you using LIBNAME XLSX and dataset. Here, is the code:

Code:

libname xlout xlsx "C:\Practice\Missing_records_in_source9.xlsx";
 
%macro libmacro2;
   %let file1="test1.dat";
   
   %do j =  1 %to 10;
       %if &j=2 or &j=4 or &j=6 %then %do;
data xlout.MissingRecs;
/* input filename $ errormsg $20.;*/
/* datalines;*/
/* file1 The file is empty;*/
/*     call symput('message',"The file is empty");*/
/* error_msg=symget(&message);*/
filename = cats(&file1,&j);
error_msg = "No records";
 
run;
    %end;
%end;
%mend libmacro2;
 
%libmacro2
 
OUTPUT in Excel:
filenameerror_msg
test1.dat6No records

 

But, want the following output:

filenameerror_msg
test1.dat2No records
test1.dat4No records
test1.dat6No records
Patrick
Opal | Level 21

@Moksha wrote:

Just now, realized that the code I have mentioned is creating an excel file if doesn't exist already. Now, the problem is that I don't know what is happening and why I am getting error (shown in the screenshot) while opening the excel file after running the macro. Can you please help me how to write to the excel file successfully?


The f-functions like fopen() or fwrite() are for interaction with simple text files. Your code does not create an Excel file but a Text file with name Missing_records_in_source.xlsx

Only because you give this file a suffix of xlsx doesn't make it an Excel Workbook.

Moksha
Pyrite | Level 9

Thank you very much for providing insights on fopen() and fwrite(). I was thinking that it is creating excel file. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 32 replies
  • 2224 views
  • 3 likes
  • 7 in conversation