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;
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
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
To use the dumb names (instead of valid SAS names that don't need ' 'n around them), you need
options validvarname=any;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.