BookmarkSubscribeRSS Feed
baynice
Calcite | Level 5

Using SAS Enterprise Guide with a point-and-click approach, I am trying to find a way to label the values taken on by a given variable.

How would you go about that?

 

You may want to know that the data were imported from an Excel file and that I was able to label the variables as desired.

I am under the impression that the Query Builder may be of interest but I still haven't found a solution...

11 REPLIES 11
PaigeMiller
Diamond | Level 26

In SAS, you can label variables, but you can't label values.

 

Perhaps you mean you want to apply a format to the values?? For example, you could have all values of 0 appear as the text FALSE and all values of 1 appear as the text TRUE.

 

Anyway, give us a concrete example of what you are trying to do. Show us briefly, a portion of your data as it exists, and then show us the desired result.

--
Paige Miller
baynice
Calcite | Level 5

Thanks for your quick response. Well, I was trying get a pie chart with meaningful expressions for the Sex variable ( 1 = "Male" and 2 = "Female" (say)). Here is the code I executed before the point-and-click graphic step:

 

PROC FORMAT;
VALUE formatsex 1 = "Male" 2 = "Female";
RUN;

 

DATA WORK.assurance;
LENGTH Origin 8 Size 8 Type 8 Claim 8 Income 8 Marital 8 Kids 8 Sex 8 ;
FORMAT Origin BEST12. Size BEST12. Type BEST12. Claim BEST12. Income BEST12. Marital BEST12. Kids BEST12.
Sex formatsex. ;
INFORMAT Origin BEST12. Size BEST12. Type BEST12. Claim BEST12. Income BEST12. Marital BEST12. Kids BEST12. Sex BEST12.;

INFILE '/saswork/SAS_work2BD500016806_odaws02-prod-ie/#LN00010'
LRECL=15
ENCODING="UTF-8"
TERMSTR=CRLF
DLM='7F'x
MISSOVER
DSD ;
INPUT
Origin : BEST32. Size : BEST32. Type : BEST32. Claim : BEST32. Income : BEST32. Marital : BEST32. Kids : BEST32. Sex : BEST32. ; RUN;

 

I managed to get the appropriate chart in this case, as evidenced by the attached file 'Capture.JPG'. However, this course of action doesn't seem to work with other similar variables I have had to study in different datasets (same informat and same number of levels). Indeed, while I manage to the change the way the values are displayed in the table, the pie chart won't display the "meaningful" levels

 

Why could this be? 

PaigeMiller
Diamond | Level 26

You'd have to show us the code for the other variables where it didn't work.

 

Please click on the running man icon, and then paste your code into the window that appears.

--
Paige Miller
baynice
Calcite | Level 5
DATA WORK.delhaize;
    LENGTH
        TYPE               8
        PROVINCE           8
        CHIFAF             8
        VENTES             8 ;
    LABEL
        TYPE             = "Store Type"
        PROVINCE         = "Province"
        CHIFAF           = "Turnover"
        VENTES           = "Sales" ;
    FORMAT
        TYPE             BEST12.
        PROVINCE         BEST12.
        CHIFAF           F12.1
        VENTES           F12.3 ;
    INFORMAT
        TYPE             BEST12.
        PROVINCE         BEST12.
        CHIFAF           BEST12.
        VENTES           BEST12. ;
    INFILE '/saswork/SAS_workF06F00013AD5_odaws01-prod-ie/#LN00010'
        LRECL=37
        ENCODING="UTF-8"
        TERMSTR=CRLF
        DLM='7F'x
        MISSOVER
        DSD ;
    INPUT
        TYPE             : BEST32.
        PROVINCE         : BEST32.
        CHIFAF           : BEST32.
        VENTES           : BEST32. ;
RUN;


PROC FORMAT ;
      VALUE typefmt 1 = 'small Delhaize'
	        2 = 'big Delhaize';
	  VALUE provincefmt  1 = 'Namur'
	              2 = 'Liège';
RUN;

DATA WORK.delhaize;
    LENGTH
        TYPE               8
        PROVINCE           8
        CHIFAF             8
        VENTES             8 ;
    LABEL
        TYPE             = "Store Type"
        PROVINCE         = "Province"
        CHIFAF           = "Turnover"
        VENTES           = "Sales" ;
    FORMAT
        TYPE             typefmt.
        PROVINCE         provincefmt.
        CHIFAF           F12.1
        VENTES           F12.3 ;
    INFORMAT
        TYPE             BEST12.
        PROVINCE         BEST12.
        CHIFAF           BEST12.
        VENTES           BEST12. ;
    INFILE '/saswork/SAS_workF06F00013AD5_odaws01-prod-ie/#LN00010'
        LRECL=37
        ENCODING="UTF-8"
        TERMSTR=CRLF
        DLM='7F'x
        MISSOVER
        DSD ;
    INPUT
        TYPE             : BEST32.
        PROVINCE         : BEST32.
        CHIFAF           : BEST32.
        VENTES           : BEST32. ;
RUN;

Thanks for your response. I am sorry I was not able to reply earlier. I have attached the original xls file. Alas, I am getting a label-free pie chart for the variable 'TYPE'  and have still not found the solution. Why could this be? How would you go about it? 

baynice
Calcite | Level 5

Please, find attached a copy of the pie chart I am getting.

TomKari
Onyx | Level 15

I tried running your code, and it worked fine for me. What problems are you experiencing? (First time I've ever created a pie chart...I had to look up instructions on SAS HELP!)

 

Tom

 

PROC FORMAT ;
      VALUE typefmt 1 = 'small Delhaize'
	        2 = 'big Delhaize';
	  VALUE provincefmt  1 = 'Namur'
	              2 = 'Liège';
RUN;

DATA WORK.delhaize;
    LENGTH
        TYPE               8
        PROVINCE           8
        CHIFAF             8
        VENTES             8 ;
    LABEL
        TYPE             = "Store Type"
        PROVINCE         = "Province"
        CHIFAF           = "Turnover"
        VENTES           = "Sales" ;
    FORMAT
        TYPE             typefmt.
        PROVINCE         provincefmt.
        CHIFAF           F12.1
        VENTES           F12.3 ;
    INFORMAT
        TYPE             BEST12.
        PROVINCE         BEST12.
        CHIFAF           BEST12.
        VENTES           BEST12. ;
    INFILE cards;
    INPUT
        TYPE             : BEST32.
        PROVINCE         : BEST32.
        CHIFAF           : BEST32.
        VENTES           : BEST32. ;
cards;
1 1 1 1
2 2 2 2
RUN;
goptions reset=all cback=white border htitle=12pt htext=10pt;  

proc gchart data=delhaize;
   pie type / other=0
              midpoints="small Delhaize" "big Delhaize"
              value=none
              percent=arrow
              slice=arrow
              noheading 
              plabel=(font='Albany AMT/bold' h=1.3 color=depk);
run;

proc gchart data=delhaize;
   pie province / other=0
              midpoints="Namur" "Liège"
              value=none
              percent=arrow
              slice=arrow
              noheading 
              plabel=(font='Albany AMT/bold' h=1.3 color=depk);
run;
baynice
Calcite | Level 5

While I modelled my code according to http://support.sas.com/kb/40/176.html, I get the attached figures (still no appropriate labels). I must be overlooking some trivial subtlety.

goptions reset=all cback=white border htitle=12pt htext=10pt;  


title1 "Types of Stores";

proc gchart data=delhaize;
   pie type / other=0
              midpoints="small Delhaize" "big Delhaize"
              value=none
              percent=arrow
              slice=arrow
              noheading 
              plabel=(font='Albany AMT/bold' h=1.3 color=depk);
run;
	
title1 "Cities";

proc gchart data=delhaize;
   pie province / other=0
              midpoints="Namur" "Liège"
              value=none
              percent=arrow
              slice=arrow
              noheading 
              plabel=(font='Albany AMT/bold' h=1.3 color=depk);
run;
TomKari
Onyx | Level 15

Ah, THAT's the problem! Formats don't round...they deal in exact values. You need to either change your values to exactly 1 and 2, or change your formats to include the values close to 1 and 2.

 

VALUE typefmt
0.5-<1.5 = 'small Delhaize'
1.5-2.5 = 'big Delhaize';

 

baynice
Calcite | Level 5
Thanks for your help!
baynice
Calcite | Level 5

For the sake of future users, it is best to treat numerical variables which are essentially categorical as character variables in order to preclude awkward barplots, pie charts, ... Hence, the PROC format step should look like this: 

PROC FORMAT;
      VALUE $typefmt '1' = 'small Delhaize'
	        '2' = 'grand Delhaize';
	  VALUE $provincefmt  '1' = 'big Delhaize'
	              '2' = 'Liège';
RUN; 

TomKari
Onyx | Level 15

One important thing to know is that when you use PROC FORMAT with no library clause, the format is placed into your WORK library. That library is deleted when your SAS session ends, therefore the format disappears.

 

You can have PROC FORMAT assign to a permanent library with syntax such as

 

PROC FORMAT lib=MyLib;

 

Tom

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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