Help using Base SAS procedures

help : read numeric variables

Reply
N/A
Posts: 0

help : read numeric variables

hi , i got a question in the follow program. how could i get the reading of variables ''ssm & sspm'': eg, ssm 5.04M as numeric as 5million and 40 thousand, and eg, sspm 0.625% as numeric as 0.625 percentage.
-------------------------------------------------------------
data projects;
input stdate : ddmmyy10. ssv : comma10. ssm idm sspm idssm sspidssm ;
format stdate ddmmyy10. ssv : comma10. ssm idm sspm idssm sspidssm ;
datalines;
10/09/2010 588,000 5.04M 807.192M 0.625% 3.567B 0.141%
09/09/2010 2,166,000 18.506M 568.513M 3.255% 4.494B 0.412%
08/09/2010 1,512,000 12.805M 548.069M 2.336% 4.094B 0.313%
;

proc print data=projects;
run;
Valued Guide
Posts: 2,174

Re: help : read numeric variables

seeking a suitable informat is a popular forum question.
Although there is an informat for percentages (PERCENT.) I was not sure about a trailing M.
Previously I have responded http://support.sas.com/forums/thread.jspa?messageID=40725#40725 pointing out a technique to get SAS to try all available informats
Checking the technique with string 1000M, the best result came from informat SIZEKMG. You might not want the result from this informat :-( as it assumes the M implies megabytes because the result I got was 1048576000.
I see no alternative other than reading that input column as a string and parsing as needed .

good luck
peterC
Contributor
Posts: 22

Re: help : read numeric variables

In case you want help with that parsing business, you could do something like this:
[pre]
data projects;
input stdate : ddmmyy10. ssv : comma10. chssm : $20. idm chsspm : $20. idssm sspidssm ;
ssm = input( substr( chssm, 1, index( chssm, 'M' ) -1 ), 5. ) * 1000000;
run;
[/pre]
Nested function calls are not always easy to read so we could break it down for readability like this:
[pre]
pos = index( chssm, 'M' ); *this finds the 'M' in '5.04M';
chnbr = substr( chssm, 1, pos -1 ); *extract the numeric characters without the 'M';
ssm = input( chnbr, 5. ) * 1000000; *read the character numbers as a number and multiply by 1000000;
[/pre]
The approach to obtaining sspm would be similar.
N/A
Posts: 0

Re: help : read numeric variables

thanks waltsmith, there a lot of beautiful people live around. god bless
N/A
Posts: 0

Re: help : read numeric variables

thanks peter c. keep the good things inside u
Ask a Question
Discussion stats
  • 4 replies
  • 116 views
  • 0 likes
  • 3 in conversation