BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
somebody
Lapis Lazuli | Level 10

I drawing some graphs (time series) with PROC SGPLOT. I use the GROUP function to have one line for each group. The value of the group in my dataset is numerical (i.e. 0,1,2,3,4,5). However, when I draw the graphs, I would like to assign some name to each group so that it displays the names instead of the numbers. 

proc sgplot data=population;
	styleattrs datacontrastcolors=(red blue orange black)
	datasymbols=(circlefilled trianglefilled squarefilled dot)
	datalinepatterns=(solid dash longdash dot) ;
	series x=year y=population/group=continent;
run;
*continent variable can be 1,2,3,4 which corresponds to Asia, Europe, America and Africa; 
*So instead of displaying 4 lines with label 1,2,3,4 on the bottom, I would like to display Asia, Europe, America, Africa;

 Well, one way is to create another variable and assign string values corresponding to the numerical value. But I dont really want to do this as it consumes memory. I hope there is a quick way with PROC SGPLOT

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Create a format with your decodes/strings, and apply the format to the data:

proc format;
  value tmp
    1="Asia"
    2=...;
run;

data population;
  set population;
  format continent tmp.;
run; 

Then it should display the strings.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Create a format with your decodes/strings, and apply the format to the data:

proc format;
  value tmp
    1="Asia"
    2=...;
run;

data population;
  set population;
  format continent tmp.;
run; 

Then it should display the strings.

somebody
Lapis Lazuli | Level 10
Thanks, but I dont want to reformat or change the value of the continent
variable. I want to keep it as numbers.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Formatting does not change the underlying data, its still the number if you remove the format.  If you don't want to format the a data and you do not want to create a new variable, then you are stuck I am afraid, you have to tell SAS somehow what values to display.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 7722 views
  • 1 like
  • 2 in conversation