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
Super User

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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