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

Team,

 

I am a new to both SAS and the forums. If I have posted this in the wrong place, let me know.

 

The code below works if I run it in parts, i.e. if I run everything separated by comments separately. Yet when I try to run the program as a whole, without singling out certain code, I receive a large number of errors. (Examples included below). These errors do not occur, and the tables I am looking for are created, if I run separately. All of the errors are centered around the custom column names I have pulled, or created. I am using SAS Studio.

 

Thank you in advance for the advice.

 

T

libname data "/home/&sysuserid/DND_Data/";
libname xlclass xlsx "/home/&sysuserid/DND_Data/Crafting Log.xlsx";
OPTIONS VALIDVARNAME=V7; 

/* Edit these StartDate and EndDate to match desired month. If all time desired use 01JAN2020 - 31DEC2030 */
%let StartDate=01may2020;
%let EndDate=31may2020;
/*Creates Three Tables:
	1. Final Item Cost Summary: Computes total cost for each item created in the given date range and sums them for a monthly Total
	2. Monthly Alchemical Creation Summary: Computes Total Unit Cost for each item then sums for a total Alchemical Creation Cost
	3. Monthly Potion Brewing Summary: Computes Brewing Cost for the dates specified.*/
data Final_Sum;
	set xlclass.'Brewing Potions'n xlclass.'Alchemical Creations'n;
	where ("&StartDate"d <= Date <= "&EndDate"d);
	'Total Reagent Cost'n = sum("Reagent Cost GP"n, 'Failure Costs GP'n);
	'Final Cost'n = Sum("Brewing Cost"n, 'Total Reagent Cost'n);
	Keep Item 'Brewing Cost'n 'Total Reagent Cost'n 'Final Cost'n;
	format 'Total Reagent Cost'n comma7.;
	format 'Brewing Cost'n comma7.;
	format 'Final Cost'n comma7.;
run;

proc sort data=Final_Sum out=Final_SumF (keep= Item 'Final Cost'n);
	by descending 'Final Cost'n;
run;

Title1 "Final Item Cost Summary";
proc print data=Final_SumF;
	var Item 'Final Cost'n;
	SUM 'Final Cost'n;			
run;

data monthly_sumA;
	set xlclass.'Alchemical Creations'n;
	where ("&StartDate"d <= Date <= "&EndDate"d);
	'Total Unit Cost'n = sum("Reagent Cost GP"n, 'Failure Costs GP'n);
	keep Item 'Reagent Cost GP'n 'Failure Costs GP'n 'Total Unit Cost'n;
	format 'Total Unit Cost'n comma7.;
run;

proc sort data=monthly_sumA out=Monthly_CostsA (keep= Item 'Reagent Cost GP'n 'Failure Costs GP'n 'Total Unit Cost'n);
	by descending 'Total Unit Cost'n descending 'Reagent Cost GP'n descending 'Failure Costs GP'n;
run;

TITLE1 "Monthly Alchemical Creation Summary";
proc print data=Monthly_CostsA;
	SUM 'Reagent Cost GP'n 'Failure Costs GP'n 'Total Unit Cost'n;			
run;

data monthly_sumB;
	set xlclass.'Brewing Potions'n;
	where ("&StartDate"d <= Date <= "&EndDate"d);
	keep Item 'Brewing Cost'n;
	format 'Brewing Cost'n comma7.;
run;

proc sort data=monthly_sumB out=Monthly_CostsB (keep= Item 'Brewing Cost'n);
	by descending 'Brewing Cost'n;
run;

TITLE1 "Monthly Potion Brewing Summary";
proc print data=Monthly_CostsB;
	SUM 'Brewing Cost'n;			
run;
title;	
libname xlclass clear;
libname data clear;

 Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @School_UD  For N literals to work, wouldn't you be needing 

OPTIONS VALIDVARNAME=ANY; 

? I vaguely remember that setting is needed? Please do correct me if i am wrong  

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

Hi @School_UD  For N literals to work, wouldn't you be needing 

OPTIONS VALIDVARNAME=ANY; 

? I vaguely remember that setting is needed? Please do correct me if i am wrong  

School_UD
Calcite | Level 5
That did the trick. Thank you for the quick response.
School_UD
Calcite | Level 5
Thank you. That did the trick. Thanks for the quick response.
ballardw
Super User

Strongly suggest that you modify the process so that you have typical SAS variable names. You will find that typo errors go way down using variable names like Total_Cost instead of 'Total Cost'n;

School_UD
Calcite | Level 5
Will adjust code to match SAS variable names. Thanks for the advice.

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
  • 6 replies
  • 655 views
  • 3 likes
  • 4 in conversation