DATA Step, Macro, Functions and more

Merge step

Accepted Solution Solved
Reply
Regular Contributor
Posts: 216
Accepted Solution

Merge step

Hi

I am running the below merge statement for two files--which are attached. When I run the statement, the values for CourtJurisdiction from each file are missrepresented in the merged file for both. In the underlying files, the value for NYS is 40426 and the value for NYC is 23213. In the merged file, the NYS is 40424 and the value for NYC is 23212.

I cannot seem to figure out why this is happening. There are many other files in this merge statement, but I just enclosed two for this example. There are also several processes that run before this statement. If anyone has any ideas, please let me know.

Paul

data overviewCourtJur2;

length County $ 50 Year 3 Filing $ 30 FilingType $ 30 AgeRange $ 30 CourtJurisdiction 3;

merge

s0FirstNysAllAge2006

S0FIRSTNYCALLAGE2006;

by County Year Filing FilingType AgeRange;

run;

Attachment

Accepted Solutions
Solution
‎03-11-2013 05:50 PM
Respected Advisor
Posts: 3,799

Re: Merge step

You cannot store values of the size you are showing in 3 byte floating point.  In general it is never a good idea to use numeric variables less that the default length 8.

View solution in original post


All Replies
Solution
‎03-11-2013 05:50 PM
Respected Advisor
Posts: 3,799

Re: Merge step

You cannot store values of the size you are showing in 3 byte floating point.  In general it is never a good idea to use numeric variables less that the default length 8.

Regular Contributor
Posts: 216

Re: Merge step

Hi Data_null

That is fine and thanks, but how would that change the values like it is doing above?

Paul

Super User
Super User
Posts: 7,070

Re: Merge step

By throwing away the rest of the number.  If you try to put 8 bytes of data into 3 bytes of storage something gets lost.

Try this little example using the value 40426.  You can see that when the three byte value is read back in the '40'x in the 4th byte is now '00'x.

data x;

  length len8 8 len3 3 ;

  len8=40426;

  len3=len8;

run;

data _null_;

  set x;

  put (len8 len8 len3 len3) ( = z5. +1 = hex16. /);

run;

len8=40426  len8=40E3BD4000000000

len3=40424  len3=40E3BD0000000000

Respected Advisor
Posts: 3,799

Re: Merge step

What Tom said.

SAS even has a function so you check it in a data step.

20         data _null_;
21            len8=40426;
22            do l=8 to 3 by -1;
23               lenl = trunc(len8,l);
24               put l= (lenl lenl ) ( = z5. +1 = hex16. /);
25               end;
26            run;

l=
8 lenl=40426  lenl=40E3BD4000000000
l=
7 lenl=40426  lenl=40E3BD4000000000
l=
6 lenl=40426  lenl=40E3BD4000000000
l=
5 lenl=40426  lenl=40E3BD4000000000
l=
4 lenl=40426  lenl=40E3BD4000000000
l=
3 lenl=40424  lenl=40E3BD0000000000
Regular Contributor
Posts: 216

Re: Merge step

Posted in reply to data_null__

OK, I got it. And thanks for examples. I just re-ran it using 8 bytes and it works fine. Thank you both.

Paul

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 236 views
  • 4 likes
  • 3 in conversation