Hi Team,
I have two tables like this.
i want to merge by the number.
but in table2 i have the same number but preceding with one or several zeros.
How can i remove them before I merge???
Regards
table1 table2
number number
6234 006234
76547 076547
70061 070061
5849 005849
Hi,
try changing "number" in table1 before merging:
data table1;
input number $;
cards;
123
2345
3489
;
data temp(rename=(new=number));
length new $6.;
set table1;
new=put(number*1,z6.);
drop number;
proc print;run;
Are they just formatted that way (in which case you don't have to do anything but compare them) or is the field with the leading zeros a text field?
Hi,
Thanks for the reply. Its just a charecter. No format given to it .its in the $10. format.
Regards
Hi,
try changing "number" in table1 before merging:
data table1;
input number $;
cards;
123
2345
3489
;
data temp(rename=(new=number));
length new $6.;
set table1;
new=put(number*1,z6.);
drop number;
proc print;run;
Hi,
Thanks. This works too....
So you want me to max length of the number variable from the other table and use Z6 format!!!
Cool.
so thwe Z6 adds leading zeros???whats is the 1* for???
If my length is 9 should I write Z9.?????
Regards
"*1" converts a character variable to a numeric variable. If "number" in table1 is a numeric variable then you don't need "*1".
z6. adds leading zeros.
If my length is 9 should I write Z9.?????
i think so, you can try.
In the mean while my friend suggested to use this on the second table to eliminate leading zeros.it works too
mrn2=substr(number,verify(number,'0'));
Regards
I would do the merge using proc sql and just convert the text on the fly. e.g.:
data table1;
input number x;
cards;
6234 1
76547 1
70061 1
5849 1
;
data table2;
informat number $10.;
input number y;
cards;
006234 2
076547 2
070061 2
005849 2
;
proc sql;
create table want as
select a.number,x,y
from table1 a
left join table2 b
on a.number=input(b.number,12.)
;
quit;
Could you also explain to me what this step is doing??
new=put(number*1,z6.);
if my length is 9 then have I to use Z9.???
Regards
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.