BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

 

Why mon field is not calculated correctly

 

data tbl1807;
input x;
cards;
1
2
3
;
run;
data tbl1806;
input x;
cards;
4
5
;
run;
data tbl1712;
input x;
cards;
7
8
9
;
run;
data combined;
set tbl1807 tbl1806 tbl1712 indsname=ds;
length mon $5;
mon=substr(scan(ds,3,','),5);
run;
3 REPLIES 3
Kurt_Bremser
Super User

Just run this:

data combined;
set tbl1807 tbl1806 tbl1712 indsname=ds;
dsname = ds;
run;

and you'll see why both the scan() and the substr() in your code:

data combined;
set tbl1807 tbl1806 tbl1712 indsname=ds;
length mon $5;
mon=substr(scan(ds,3,','),5);
run;

can't work.

Maxim 3: Know your Data. Can be extended to "know your variables" 😉

muratatik
Obsidian | Level 7

I assumed you are trying to extract numeric value of indsname.

 

 

data combined;
set tbl1807 tbl1806 tbl1712 indsname=ds;
dsname=ds;
mon=compress(dsname,,'ap');
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1698 views
  • 1 like
  • 3 in conversation