BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fengyuwuzu
Pyrite | Level 9

I have special characters in my data,  ≥ and ≤. without any format, I can produce the freq table as below:

 

Capture.PNG

 

But I want to order the age groups, so they are in order, and tried to use the following code to create a format. However, the format does not work.

 

I found a old post in 2013 mentioning running SAS in unicode mode, but I do not know how to run SAS in unicode mode. Can nay one help? Thank you.

 

PROC FORMAT;
   VALUE $ typefmt 
        1 = '(*ESC*){unicode '"2264"x} 20'
        2 = '21-25 '
        3 = '26-30 ' 
	4 = '(*ESC*){unicode "2265"x} 31'
;
quit;
proc freq data=new_vvnv;
tables age_group*status /nocol  ;
format age_group $typefmt.;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

I think, you could simply sort

 

by age;

rather than by age_group age to achieve the desired result.

 

 

Still, it would be interesting to find out why sorting by AGE_GROUP, which should contain values '1', '2', '3' and '4', fails to bring '1' to the top. (PROC SORT always sorts by unformatted values.) My next step would be a closer look at the unformatted values of AGE_GROUP.

 

View solution in original post

8 REPLIES 8
LinusH
Tourmaline | Level 20
I'm not following.
The freq output looks like the code you are supplying?
And from this code it seems that your data contains 1, 2, 3 and 4 - not any special characters...?
Data never sleeps
Cynthia_sas
SAS Super FREQ

Hi: Since you did not provide data to test with I made some fake data from SASHELP.CLASS. But using ORDER=DATA (after I'd sorted the file) worked for me to put the AGE_GROUP in order.

 

cynthiause_order_data_freq.png

fengyuwuzu
Pyrite | Level 9

I got the following error:

 

42   PROC FORMAT;
43      VALUE $ typefmt
44           1 = '(*ESC*){unicode '"2264"x} 20 '
                                               --------------
                                               49
45           2 = '21-25 '
                        --------------
                        49
46           3 = '26-30 '
                    ---
                    22
                    76
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white
             space between a quoted string and the succeeding identifier is recommended.

ERROR 22-322: Syntax error, expecting one of the following: (, ',', =.

ERROR 76-322: Syntax error, statement will be ignored.

47       4 = '(*ESC*){unicode "2265"x} 31 '
48   ;
49   quit;
50   proc freq data=new_vvnv;
51   tables age_group*status /nocol  ;
52   format age_group $typefmt.;
53   run;

FreelanceReinh
Jade | Level 19

Please remove the single quote in

... unicode '"2264"x ...
fengyuwuzu
Pyrite | Level 9

Here is the data

 

Obs Age Age_Group 
1 21 21-25 
2 21 21-25 
3 21 21-25 
4 21 21-25 
5 21 21-25 
6 21 21-25 
7 21 21-25 
8 21 21-25 
9 21 21-25 
10 21 21-25 
11 21 21-25 
12 21 21-25 
13 22 21-25 
14 22 21-25 
15 22 21-25 
16 22 21-25 
17 22 21-25 
18 23 21-25 
19 23 21-25 
20 23 21-25 
21 23 21-25 
22 23 21-25 
23 23 21-25 
24 24 21-25 
25 24 21-25 
26 24 21-25 
27 24 21-25 
28 24 21-25 
29 24 21-25 
30 25 21-25 
31 25 21-25 
32 25 21-25 
33 25 21-25 
34 25 21-25 
35 26 26-30 
36 27 26-30 
37 27 26-30 
38 28 26-30 
39 28 26-30 
40 18 ≤ 20 
41 18 ≤ 20 
42 18 ≤ 20 
43 18 ≤ 20 
44 18 ≤ 20 
45 18 ≤ 20 
46 18 ≤ 20 
47 18 ≤ 20 
48 18 ≤ 20 
49 18 ≤ 20 
50 19 ≤ 20 
51 19 ≤ 20 
52 19 ≤ 20 
53 19 ≤ 20 
54 19 ≤ 20 
55 19 ≤ 20 
56 19 ≤ 20 
57 19 ≤ 20 
58 19 ≤ 20 
59 19 ≤ 20 
60 19 ≤ 20 
61 19 ≤ 20 
62 19 ≤ 20 
63 19 ≤ 20 
64 20 ≤ 20 
65 20 ≤ 20 
66 20 ≤ 20 
67 20 ≤ 20 
68 20 ≤ 20 
69 20 ≤ 20 
70 20 ≤ 20 
71 20 ≤ 20 
72 20 ≤ 20 
73 20 ≤ 20 
74 20 ≤ 20 
75 20 ≤ 20 
76 31 ≥ 31 
77 35 ≥ 31 

 

I used the following code, now format is okay (thanks for pointing out a single quote in original code), but the sort does not work. After sort, 21-25 is still the first age group.

 

PROC FORMAT;
   VALUE $ typefmt 
        1 = '(*ESC*){unicode "2264"x} 20 '
        2 = '21-25 '
        3 = '26-30 ' 
	4 = '(*ESC*){unicode "2265"x} 31 '
;
quit;

proc sort data=new_vvnv;
format age_group $typefmt.;
by age_group age;
run;


proc freq data=new_vvnv order=data;
tables age_group*status /nocol  ;
format age_group $typefmt.;
run;

 

 

 

FreelanceReinh
Jade | Level 19

I think, you could simply sort

 

by age;

rather than by age_group age to achieve the desired result.

 

 

Still, it would be interesting to find out why sorting by AGE_GROUP, which should contain values '1', '2', '3' and '4', fails to bring '1' to the top. (PROC SORT always sorts by unformatted values.) My next step would be a closer look at the unformatted values of AGE_GROUP.

 

fengyuwuzu
Pyrite | Level 9

yes simply sort by age works. Thanks

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!

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
  • 8 replies
  • 14198 views
  • 1 like
  • 4 in conversation