Again, all these efforts to convert character to numeric is because I cannot use a character variable as an analysis in proc tabulate/ proc report. var1 is my ID and I would like to get the count of Id's for my classification variable. Is there a way I could use character variable in proc tabulate/report for analysis? I would not worry about the conversion then.
If you assign the variable a length of 3, but end up with a length of 8, that tells me the length is already set. PROC APPEND adds the variable (with a length of 3), but has to expand that to a length of 8 because the base data set that already exists has a length of 8 for the same variable.
The extreme changes in the values aren't explainable based on what you have shown so far.
I can't speak for PROC REPORT, but PROC TABULATE allows you to use both character and numeric variables in the CLASS statement. The VAR statement is limited to numerics only. You would have to check this, but I believe it is possible to get the N statistic (a count) without specifying any VAR variables at all.
Appearance for extremely large or small varaibles will end up as exponential notation if you do not specify another format. Please see this code for a very brief example:
data junk;
x=123456789123458;
run;
proc print;
run;
proc print;
format x best16.;
run;
Proc tabulate will handle character looking numerics just fine as a CLASS variable. Just make sure that if you specifically request a statistic for them that you only request the N types: N, PCTN, ROWPCTN, COLPCTN and PAGEPCTN.
But in the example I mentioned above, the large value, var1 appears as exponential inspite of specifying the format best16.
%macro tname(tname);
%let var_fmt=group_test;
%do;
data temp_test;
set x.&tname;
length name $ 30;
name="&tname";
length val_fmt $10.;
val_fmt = put(&var_fmt,$test_group.);
member1= input(var1,best16.); /* member1 appears in exponential inspite of specifying the format here */
run;
proc append base=one_test data=temp_test force;
run;
%end;
%mend tname;
And, Proc tabulate I just realized it works fine without using the var statement and just adding it in the class statement. I dont have any statistic that requires numeric value. Just needed the count, hence worked well.
I see no place where you assign a Format to var1.
If you are referring to this line:
member1= input(var1,best16.);
The BEST16. is being used as an INFORMAT or instruction on reading a value. Run proc contents on that data set and I bet you will find that the INFORMAT will be BEST16, or possibly just 16. if all the values are integer, and the FORMAT will be BEST12. So when you have more than 12 digits in a value SAS will display the "best" 12 that are available which means exponential notation. And since the Exponent part E10 or whatever takes 3 of the display spaces then there are a maximum of 9 other characters to display.
Add
Format member1 best16. ;
to the code and see the result.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: