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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 604 views
  • 0 likes
  • 3 in conversation