Data not pictures. I'm not going to create data from pictures to write code.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.
@cougar300 wrote:
Why is &&Name&i resolving fine for the put statement, but not for the if then comparison line?
Hi @cougar300,
While the main problems with your code have been pointed out already, let me just answer the above question: In the case of &&Name&i resolving to A/O Stuff the reason was that the macro processor interpreted the slash in "A/O Stuff" as the division operator, which is valid only with numeric operands, not with character operands such as A and O. This is what the error message "A character operand was found in the %EVAL function or %IF condition where a numeric operand is required." referred to. (This would not have occurred with &&Name&i resolving to Brand A, which is what your initial post suggested.) It is indeed somewhat confusing that the error message ("The condition was: brand = &&Name&i") does not resolve the macro variable reference and thus hides the culprit (the slash in this case).
If the comparison made sense in an %IF condition, double quotes or macro quoting functions (such as %BQUOTE) would need to be applied in order to avoid the wrong interpretation of the slash.
Thank you
the "/" making it attempting a numeric conversion makes sense. That clarifies that part, at least.
If anyone can easily turn this starting data into the blue part shown in the above picture, please let me know.
thanks
data WORK.start;
infile datalines dsd truncover delimiter=',';
input Brand:$8. Amount:32. Ratio:32.;
datalines;
Brand A,20,.4
Brand B,16,.5
Brand C,12,.25
Brand D,8,.25
Brand E,14,0
;
Like this:
data WORK.start;
infile datalines dsd truncover ;
input Brand $ Amount Ratio ;
datalines;
Brand A,20,.4
Brand B,16,.5
Brand C,12,.25
Brand D,8,.25
Brand E,14,0
;
proc sql;
create table want as
select a.brand,a.amount,a.ratio
, b.brand as brand2,b.amount*a.ratio as new_amount
from start a
, start b
;
quit;
proc report data=want ;
columns brand amount ratio new_amount,brand2;
define brand / group;
define amount / group;
define ratio / group;
define brand2 / across ' ';
define new_amount / sum;
run;
Thank you so much!
If I want this to be different by store, I assume I can just add "by store" in the SQL?
Either way.
Thanks!
One other Q if you are here -
The report is what I want, but I need it in a dataset.
When I put out=dataset into the proc report, everything is there, but instead of the var names being Brand A through Brand E, the var names are _C4_ through _c8_.
Can I get a dataset to look like the report does?
Thanks again!
I will try to take the output and make it what I need it to be.
The reason for the var name is that I need to sum each of them across all stores, so if one store has 5 brands and another store has a different 5 brands I cant have them both being labeled c4-c8. There can be from 1-20 brands and in the end I need to sum across all of them, so having the actual brand there would be best.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.