BookmarkSubscribeRSS Feed
Sarojkumar
Calcite | Level 5
I have two datasets.I have to create an output dataset from these two with the condition that var2 of dataset1 should match the var2 of dataset2. Only concern is Var2 is $9 here and $32 in the second dataset.

Example:

var1 var2($9)
-----------------------
1 0000283
2 731823
3 1073388
4 12


varX var2($32)
-----------------------
1 000002837
2 000731828
3 001073388
4 000161499

How to get the result as :

var1 varx
==========
3 3

I tried left, trim, input and put fuctions but i am getting absurd results. Thats becaue when I convert the character to numeric for comparasion purpose, the values wiht more than 8 characters are trimmed and so wrong matching ouptut is generate. Is there any way I can compare this two variable.

Note : Size of both vairbles are $9 and $32 and the values in this are starting from 1 character to any.

Thanks for your help...
5 REPLIES 5
DanielSantos
Barite | Level 11
Sorry, I initially misunderstood the problem.

Here's my modified post.

Create a view over the each dataset and convert the variable (alpha) to an numeric equivalent.
[pre]
proc sql noprint;
create view X1 as
select var1, input(var2,best.) as VAR2 from INDATA1;
quit;

proc sql noprint;
create view X2 as
select varX, input(var2,best.) as VAR2 from INDATA2;
quit;
[/pre]
then merge the views into a single dataset.

Should work.

Cheers from Portugal

Daniel Santos @ www.cgd.pt
Sarojkumar
Calcite | Level 5
Thanks Daniel..This works...Can you please tell me how to convert a character variable to numeric vairable if the character variable is more that 8 characters...

Ex. '123456789' or '1234567890' etc
abdullala
Calcite | Level 5
if only problem is leading 0 then you may use substr and not having to mess up with type switch from char to num.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Conversion can be done with the DATA step assignment statement, using the INPUT function and the appropriate INFORMAT/length - example below:


17 data _null_;
18 x = input('123456789012345',15.);
19 put x= comma20. / x= best.;
20 run;

x=123,456,789,012,345
x=1.2345679E14
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

To append leading zeros, use the Znn. SAS format, and if you must convert to a character type variable, use the SAS PUT function with Znn. format in an assignment statement.

Scott Barry
SBBWorks, Inc.
Sarojkumar
Calcite | Level 5
Thank you all, it worked...

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1577 views
  • 0 likes
  • 4 in conversation