Dear SAS Community,
I needed to alter the order of the months for the variable 'Harvest' (starting with month 11 instead of 1) for a particular Variety when using proc sgpanel so I did it with proc format. However, once I applied this formatting, it applies for the rest of the varieties too, which I don't want. How can I make sure that this formatting only applies for these varieties (I49L and Hass) but not for others? I would greatly appreciate your help!
Not sure what you mean.
Could you share a picture of the result and explain what part is different than what you want?
Could you share the data you use? Preferable as small as necessary to show the issue.
Thank you for your quick reply Tom!
I want the variety I49L to start with Harvest month 11 (Nov) in the graph, so I did modified that with proc format, but if I want the next variety (GEM) to start with Harvest month 1 (Jan) to 8, then SAS keeps using the formatting from the previous variety (I49L), as you can see in the graph. I hope that helps.
proc sgpanel data=GEM;
where Harvest in(1,3,4,5,6,8) and Variety in('GEM','Hass');
panelby Harvest/ onepanel spacing=5 novarname;
styleattrs DATACONTRASTCOLORS=(BLUE red);
vline Wks/lineattrs=(pattern=solid thickness=2) response=DTR group=Variety grouporder=data markers stat=mean ;
rowaxis values=(0 to 20 by 2) ;
run;
The format is applied to the values of the variable it is attached to. The values of other variables has no impact.
If you want the format to display the same values then make sure to code the VARIABLE with the same values.
For example you might test the values of the other variable when making decisions about how to assign the values.
data new;
set one;
where Variety in('I49L','Hass');
if Variety='I49L' then do;
if (Harvest eq 11) then tag=1;
else if (Harvest eq 12) then tag=2;
else if (Harvest eq 1) then tag=3;
else if (Harvest eq 2) then tag=4;
else if (Harvest eq 3) then tag=5;
else if (Harvest eq 5) then tag=6;
else tag=.;
end;
else do;
* Put code to create proper values of TAG for the 'Hass' variety here ;
end;
run;
Please be more detailed about what you are doing.
What are the variable names and types? What do the values mean? What role do they play in the graph you want to create?
Based on the code and the picture my GUESS is that in the dataset GEM you have a format attached to the numeric variable HARVEST that converts the values 1 to 'Nov', 3 to 'Jan' , ... 6 to 'May' and 8 to '8'. I make this guess because in the WHERE statement you limit the set of observations to the ones with those values of HARVEST. If you would like to make this graph using a different format for HARVEST then add a FORMAT statement to the graph. If you would like to simply remove the format and have the raw values displayed then do not include a format specification in the FORMAT statement.
format harvest ;
But that is just a guess.
I can make a graph that sort of looks like that using data like this:
data gem ;
length Harvest $9 Variety $4 Wks 8 DTR 8 ;
input Harvest -- DTR;
cards;
2020-2021 Haas 1 6.5
2020-2021 Haas 3 5.9
2020-2021 Haas 5 5.8
2020-2021 Haas 8 4.3
2020-2021 GEM 3 6.1
2020-2021 GEM 5 5.7
2020-2021 GEM 8 6.2
;
proc sgpanel data=GEM;
panelby Harvest/ onepanel spacing=5 novarname;
styleattrs DATACONTRASTCOLORS=(BLUE red);
vline Wks
/lineattrs=(pattern=solid thickness=2)
response=DTR
group=Variety
grouporder=data
markers
stat=mean
;
rowaxis values=(0 to 20 by 2) ;
run;
Share your data (use a data step like my example above) so we can see what you are actually working with.
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →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.