DATA Step, Macro, Functions and more

special characters ≥ and ≤ and format

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

special characters ≥ and ≤ and format

[ Edited ]

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;

 


Accepted Solutions
Solution
‎05-03-2016 09:54 AM
Trusted Advisor
Posts: 1,115

Re: special characters ≥ and ≤ and format

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


All Replies
Super User
Posts: 5,256

Re: special characters ≥ and ≤ and format

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
SAS Super FREQ
Posts: 8,742

Re: special characters ≥ and ≤ and format

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

Super Contributor
Posts: 312

Re: special characters ≥ and ≤ and format

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;

Trusted Advisor
Posts: 1,115

Re: special characters ≥ and ≤ and format

Please remove the single quote in

... unicode '"2264"x ...
Super Contributor
Posts: 312

Re: special characters ≥ and ≤ and format

Thank you.
Super Contributor
Posts: 312

Re: special characters ≥ and ≤ and format

[ Edited ]

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;

 

 

 

Solution
‎05-03-2016 09:54 AM
Trusted Advisor
Posts: 1,115

Re: special characters ≥ and ≤ and format

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.

 

Super Contributor
Posts: 312

Re: special characters ≥ and ≤ and format

yes simply sort by age works. Thanks

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 484 views
  • 1 like
  • 4 in conversation