BookmarkSubscribeRSS Feed
swayto
Fluorite | Level 6

data work.input;
input Deposit Amount;
datalines;
1 10,000.00
2 $3.4k
3 $9.3e3
4 $7500
;
data work.output;
set work.input;
Num_Amout=input(amount,comma9.);
run;
What output will be created by this program, Deposit and amount are character variable?

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

No. They are numeric variables unless you specify otherwise. In the code below they are character (notice the $).

 

And regarding your question: Run it and see? 🙂

 

data work.input;
input Deposit $ Amount $;
datalines;
1 10,000.00
2 $3.4k
3 $9.3e3
4 $7500
;
Kurt_Bremser
Super User

A clear case for Maxim 4. Simply try it.

Then apply Maxim 2 (Read the Log), and then Maxim 3 (Know Your Data). Inspect the columns in the data grid, or run a proc contents.

 

You will note that your first step results in missing values only for amount because you have 4 different ways of providing numeric data, all 4 of which are not covered by the default informat for numbers.

So you'll probably end up with reading that column as character and then doing a conditional conversion, depending on certain markers found in the string.

An example that works for your 4 datalines:

data work.input;
input Deposit _Amount :$15.;
_amount = compress(_amount,'$,');
if substr(_amount,length(_amount),1) = 'k'
then amount = input(substr(_amount,1,length(_amount)-1),best15.) * 1000;
else amount = input(_amount,best15.);
datalines;
1 10,000.00
2 $3.4k
3 $9.3e3
4 $7500
;
run;

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 776 views
  • 0 likes
  • 3 in conversation