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

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.

Astounding
PROC Star

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.

vsharipriya
Fluorite | Level 6
This helps. Thanks a lot !
ballardw
Super User

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.

 

vsharipriya
Fluorite | Level 6

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.

ballardw
Super User

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.

vsharipriya
Fluorite | Level 6
I thought the statement length member1 16. should do the same thing but did not realize I should give format statement explicitly again. Adding the like Format member1 best16. worked well.

Thanks ballardw

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
  • 21 replies
  • 5514 views
  • 2 likes
  • 3 in conversation