BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

When I run the below code, I got the report generated perfectly but got one error message - "ERROR: The value 000485 is not a valid SAS name."

Can anyone help me on this? Thanks.

 


DATA FINAL2;
INPUT SALES_STAFF_ID $ PD $ PAYOUT;
DATALINES;
000485 ABC 1000
;
run;

 

data _null_;
set FINAL2 end=eof;
by SALES_STAFF_ID;
flag+1;
call symput('var'||put(flag,8. -L),SALES_STAFF_ID);
end;
if eof then call symput('tot',put(flag,8. -L));
run;

%macro groups(dsn,byvar);
%do i=1 %to &tot;
data "&&var&i";
set &dsn;
if &byvar="&&var&i" then output;
run;

proc sql noprint;
select distinct Sales_STAFF_ID
into :ORDERedvars2 separated by ""
from FINAL2
where SALES_STAFF_ID eq "&&var&i";
quit;

options nodate nonumber center;
ods escapechar="^";
title;
footnote;

%LET OUTPATH = D:\TESTING-&orderedvars2..PDF;

ODS PDF FILE="&OUTPATH" compress=9 startpage=NO;

options nocenter;
options orientation=landscape papersize=A3;
*options orientation=portrait papersize=A3;
ods pdf startpage=now;
ods pdf style=analysis;

ODS TEXT = "OVERALL RESULT";
PROC PRINT DATA=FINAL2(WHERE=(SALES_STAFF_ID = "&&var&i")) NOOBS LABEL;
LABEL SALES_STAFF_ID='ID'
PD="POST"
PAYOUT="Payout";
FORMAT PAYOUT DOLLAR18.2;
RUN;

ODS PDF CLOSE;
ODS LISTING;
ODS LISTING CLOSE;

%end;
%mend groups;

options mprint symbolgen;
%groups(FINAL2,SALES_STAFF_ID)

6 REPLIES 6
PaigeMiller
Diamond | Level 26

You are creating a macro variable with the value 000485 (from SALES_STAFF_ID) and then you are using that macro variable with value 000485 to be a data set name, which cannot be a data set name, data set names must begin with a character or an underscore. Also, you wouldn't put the macro variables in quotes in the DATA statement.

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

A dataset name cannot begin with a number

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why are you doing all that in the first place?  It looks like your creating a file/report for each subject in the first datastep, so why not (also please avoid using all upper case or mixing, it makes it hard to read):

data final2;
  input sales_staff_id $ pd $ payout;
datalines;
000485 ABC 1000
;
run;

data _null_;
  set final2;
  call execute('ods pdf file="d:\testing-'||strip(sales_staff)||'.pdf" compress=9 startpage=no;
                options nocenter;
                options orientation=landscape papersize=a3;
                ods pdf startpage=now;
                ods pdf style=analysis;
                ods text = "overall result";
                proc print data=final2(where=(sales_staff_id ='||strip(sales_staff)||')) noobs label;
                  label sales_staff_id="id"
                  pd="Post"
                  payout="Payout";
                  format payout dollar18.2;
                run;
                ods pdf close;');
run;
PaigeMiller
Diamond | Level 26

@RW9 wrote:

Why are you doing all that in the first place?  It looks like your creating a file/report for each subject in the first datastep, so why not (also please avoid using all upper case or mixing, it makes it hard to read):


Perhaps the user thinks, rightly so, that this use of macros is a supported tool in SAS, that should produce the answer (s)he wants, if he can fix his code; and along the way learn something about how macros work. Also, the SAS documentation has lots of examples of writing macro code to perform tasks similar to this, why shouldn't the user do this?

 

 

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Indeed, and generates a lot more code to do looping which is already taken care of by the data step.  Another version would be to write the macro, then use the datastep to generate the calls to the macro, again avoiding the need to dop looping and macro lists.  It is hardly my fault if this is not in the documentation as I have no control over that, and people will not know this is it is not shown.  You can also learn a lot more seeing various methods of doing the same thing.

PaigeMiller
Diamond | Level 26

@RW9 wrote:

Indeed, and generates a lot more code to do looping which is already taken care of by the data step.


Why is this a concern? Shouldn't the initial concern be to get the code to do what you want?

 

You can also learn a lot more seeing various methods of doing the same thing.

 

You could approach the situation in a little less confrontational way. Instead of "Why are you doing all that in the first place?" you could indicate that a better approach is ... and then explain why it is better ... your tone doesn't really lend itself to have people consider your suggestion.

--
Paige Miller

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 851 views
  • 0 likes
  • 4 in conversation