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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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