BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ballardw
Super User

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.

FreelanceReinh
Jade | Level 19

@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.

cougar300
Calcite | Level 5

Thank you

 

the "/" making it attempting a numeric conversion makes sense.  That clarifies that part, at least.

 

 

cougar300
Calcite | Level 5

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
;

Tom
Super User Tom
Super User

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;

image.png

cougar300
Calcite | Level 5

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!

 

 

cougar300
Calcite | Level 5

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!

Tom
Super User Tom
Super User
Why would you want a dataset with data (BRAND name) in metadata (variable name)?
Use PROC TRANSPOSE.
cougar300
Calcite | Level 5

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.

Tom
Super User Tom
Super User
Nope. Leave the data in the tall format and that issues doesn't exist.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 24 replies
  • 1053 views
  • 2 likes
  • 7 in conversation