BookmarkSubscribeRSS Feed
EinarRoed
Pyrite | Level 9

I've got a table with around 50 variables. Roughly 30 numerics, and 20 chars. Need to create a checksum that's unique for all the 50 variables.

 

I'm currently casting the 30 numerics to character. Then I combinine all 50 char values into 1 variable that I use in SHA256 to create the actual checksum.

 

I'd like to make this more dynamic. So that I don't need to use 1 PUT-statement for each variable I cast from numeric to character.

 

I've written code that identifies all numeric variables and creates a temporary table for them. Is there a way to tell SAS to "cast all variables in this table to character"?

2 REPLIES 2
maguiremq
SAS Super FREQ

Can you provide some example data? One way I think off the top of my head is through an array.

 

Here's what I'm talking about:

 

data have;
input a b c d;
datalines;
1 2 3 4
;
run;

data want;
	set have;
	array all_num [*] _numeric_;
	array all_char [*] $1. chars1 - chars4;
	do i = 1 to dim(all_num);
		all_char[i] = put(all_num[i], 1.);
	end;
run;
data_null__
Jade | Level 19

Could you use CATS to do the heavy lifting?

 

data class2;
   set sashelp.class;
   length chk $256;
   chk = sha256(cats(of name--weight));
   run;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 771 views
  • 3 likes
  • 3 in conversation