BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bbibbi_yc
Calcite | Level 5

Hi, this is my code about proc format and the outcome.

 

截圖 2023-09-27 下午4.23.42.png截圖 2023-09-27 下午4.23.22.png

 

 

And I got a note:

NOTE: Format EDU is already on the library WORK.FORMATS.
NOTE: Format EDU has been output.
 
I am wondering where is my outcome about the proc format.
Thank u.
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Your format MAR does not have a $ in the name. Same for EDU. In addition, there is no need to create a whole new data set to assign formats. The entire code you have written can be simplified

 

filename refile_1 '/home/...';
proc import datafile=refile_1 out=homework dbms=xlsx; 
getnames=yes;
run;
proc format;
    value edu 1='Illiteracy' 2='Elementary' 3='Junior' 4='Senior High' 5='College' 6='Graduate'; 
    value mar 1='Single' 2='Married' 3='Widowed' 4='Divorced'; /* Please note the use of capital letters in the formatted values */
run;
data homework_3;
    set homework;
    format edu edu. mar mar.;
    label edu='Educational Level' mar='Marital Status'; /* Please note the use of capital letters in the labels */
run;
proc freq data=homework_3;
    tables edu mar;
run;

 

or even simpler, this only requires one data set named HOMEWORK

 

 

filename refile_1 '/home/...';
proc import datafile=refile_1 out=homework dbms=xlsx; 
getnames=yes;
run;
proc format;
    value edu 1='Illiteracy' 2='Elementary' 3='Junior' 4='Senior High' 5='College' 6='Graduate'; 
    value mar 1='Single' 2='Married' 3='Widowed' 4='Divorced'; /* Please note the use of capital letters in the formatted values */
run;
proc datasets library=work nolist;
    modify homework;
    format mar mar. edu edu.;
    label edu='Educational Level' mar='Marital Status'; /* Please note the use of capital letters in the labels */
run;
quit;
proc freq data=homework;
    tables edu mar;
run;
--
Paige Miller

View solution in original post

17 REPLIES 17
Astounding
PROC Star
You copied some notes you received about the EDU format. Where did you find those notes?
bbibbi_yc
Calcite | Level 5

In the diary.

And now I use another ways but still not solve the problem.

Thank u.

螢幕擷取畫面 2023-09-27 231808.png螢幕擷取畫面 2023-09-27 231944.png

Reeza
Super User
Different problem.

$EDU and EDU are different formats.

$ indicates a character format.

Your formats should be EDU and MAR

format EDU edu. Mar mar.;

For simplicity, I recommend not using the same name for your format and variable, I usually add the _fmt at the end.

edu_fmt and mar_fmt are clearer.

I'd show you how that works but I'm not going to type out your code. Please post your code as text in the future.
PaigeMiller
Diamond | Level 26

Your format MAR does not have a $ in the name. Same for EDU. In addition, there is no need to create a whole new data set to assign formats. The entire code you have written can be simplified

 

filename refile_1 '/home/...';
proc import datafile=refile_1 out=homework dbms=xlsx; 
getnames=yes;
run;
proc format;
    value edu 1='Illiteracy' 2='Elementary' 3='Junior' 4='Senior High' 5='College' 6='Graduate'; 
    value mar 1='Single' 2='Married' 3='Widowed' 4='Divorced'; /* Please note the use of capital letters in the formatted values */
run;
data homework_3;
    set homework;
    format edu edu. mar mar.;
    label edu='Educational Level' mar='Marital Status'; /* Please note the use of capital letters in the labels */
run;
proc freq data=homework_3;
    tables edu mar;
run;

 

or even simpler, this only requires one data set named HOMEWORK

 

 

filename refile_1 '/home/...';
proc import datafile=refile_1 out=homework dbms=xlsx; 
getnames=yes;
run;
proc format;
    value edu 1='Illiteracy' 2='Elementary' 3='Junior' 4='Senior High' 5='College' 6='Graduate'; 
    value mar 1='Single' 2='Married' 3='Widowed' 4='Divorced'; /* Please note the use of capital letters in the formatted values */
run;
proc datasets library=work nolist;
    modify homework;
    format mar mar. edu edu.;
    label edu='Educational Level' mar='Marital Status'; /* Please note the use of capital letters in the labels */
run;
quit;
proc freq data=homework;
    tables edu mar;
run;
--
Paige Miller
bbibbi_yc
Calcite | Level 5

Hello, thank you for your response. I followed your advice, but still couldn't achieve the results I expected.

Why weren't the numbers replaced in the form?

Thank u.

螢幕擷取畫面 2023-09-29 141706.png螢幕擷取畫面 2023-09-29 141739.png

Kurt_Bremser
Super User

@bbibbi_yc wrote:

Hello, thank you for your response. I followed your advice, but still couldn't achieve the results I expected.

Why weren't the numbers replaced in the form?


Because you did not use the formats in the FREQ procedure, as was already mentioned.

 

Please do not post pictures of code or logs in the future. Always (ALWAYS) copy/paste the text into the appropriate windows (see your "welcome" email when you signed up to the forum). This allows us to quickly annotate and correct your work.

Reeza
Super User

@Kurt_Bremser wrote:

@bbibbi_yc wrote:

Hello, thank you for your response. I followed your advice, but still couldn't achieve the results I expected.

Why weren't the numbers replaced in the form?


Because you did not use the formats in the FREQ procedure, as was already mentioned.

 

Please do not post pictures of code or logs in the future. Always (ALWAYS) copy/paste the text into the appropriate windows (see your "welcome" email when you signed up to the forum). This allows us to quickly annotate and correct your work.


If the formats are applied at the data set level, proc freq should be using them. Either it's a language incompatibility issue or there's an error in the log somewhere we can't see are my guesses. For language incompatibility, I've seen SAS Studio not work correctly in Chinese keyboard/dialects.

bbibbi_yc
Calcite | Level 5
I see. Thanks for your opinion!
Reeza
Super User

Post the log as well to indicate if something went wrong somewhere.

 

Also, test this use case which should work. 

 

proc format;
value $ sex_fmt
'F' = 'Female'
'M' = 'Male';

value age_fmt
low - 9 = 'Child'
10-12 = 'Tween'
13-16 = 'Teen'
16 - high = 'Young Adult';
run;

data class;
set sashelp.class;
format age age_fmt. sex $sex_fmt.;
run;

proc freq data=class;
tables age sex;
run;

@bbibbi_yc wrote:

Hello, thank you for your response. I followed your advice, but still couldn't achieve the results I expected.

Why weren't the numbers replaced in the form?

Thank u.

螢幕擷取畫面 2023-09-29 141706.png螢幕擷取畫面 2023-09-29 141739.png


 

PaigeMiller
Diamond | Level 26

NOTE in the log does not indicate a problem. It is just providing information.

 

In PROC FREQ, you have to assign the format(s) to the variable(s). You have not done that. I'm sure that your class notes explain how to do that.

 

Side note: if you are going to assign a format, use proper proper capitalization, proper grammar and so on. For example

 

value mar 1='Single' ... ;

 

The reason you use formats is to make something more readable and more meaningful; if you want to make things more readable, use proper capitalization and grammar.

--
Paige Miller
donricardo
SAS Employee

Hi bbibi:

A few SAS procedures do not generate any reports by themselves, proc sort and proc format among them.   The only way you'll know they've compiled is via a note in your log.

rich

bbibbi_yc
Calcite | Level 5

Hello, that means I can't see the 'Single' or other else in my table?

It sounds like a stupid question, but I really don't understand. Thank you for your patient response.

Tom
Super User Tom
Super User

@bbibbi_yc wrote:

Hello, that means I can't see the 'Single' or other else in my table?

It sounds like a stupid question, but I really don't understand. Thank you for your patient response.


Formats impact how the value is DISPLAYED, not the value that is STORED.

So if you have a format that display the number 1 as the string Single then the number 1 is what is stored in the dataset.  If the format is being used when you "look" at the data then you will see Single but the value in the dataset is still the number 1.

 

So in the tabular report (what I normally mean when I use the word TABLE) produced by PROC FREQ the formatted value is displayed.  So if the variable has a format attached that converts 1 to Single then Single will show up in the report.  If there is no format attached to a number than SAS will normally display it using the BEST12. format.

bbibbi_yc
Calcite | Level 5
/*import data*/
Filename refile_1 '/home/u63518324/sasuser.v94/Epi_test.xls';
proc import datafile=refile_1
out=homework
dbms=xls;
getnames=yes;
run;

/*change label, format*/

proc format;
    value edu 1='Illiteracy' 2='Elementary' 3='Junior' 4='Senior High' 5='College' 6='Graduate'; 
    value mar 1='Single' 2='Married' 3='Widowed' 4='Divorced';
run;
data homework_3;
    set homework;
    format edu edu. mar mar.;
    label edu='Educational Level' mar='Marital Status';
run;
options nofmterr;
proc freq data=homework_3;
    tables edu mar;
run;

Hello, this is my code. I'm wondering where the problem is that prevents me from opening my data display results. Also, the following error still appears in the log.

 85             format edu edu. mar mar.;
                           ____
                           484
 NOTE 484-185: Format $EDU was not found or could not be loaded.
 
 85       !     format edu edu. mar mar.;
                                    ____
                                    484
 NOTE 484-185: Format $MAR was not found or could not be loaded.

Thank u so much.

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
  • 17 replies
  • 1879 views
  • 0 likes
  • 8 in conversation