🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-03-2021 02:01 AM
(571 views)
I have a data with a column of percentages, the column in inconsistent. Some obs are discrete values like X% and some are ranges x % - y%. I have to take average of range obs. How can I do that ? Below is an example of my problem
data _null_;
input pct $;
cards;
15%
5
30
10-15%
;
run;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If below works for you will depend on your actual data.
I've made the assumption that all values are in percent.
data have;
input pct $;
cards;
15%
5
30
10-15%
;
data want(drop=_:);
set have;
length pct_n 8;
pct=compress(pct,' %');
_words=countw(pct,'-');
do _i=1 to _words;
pct_n=sum(pct_n,input(scan(pct,_i,'-'),best32.));
end;
pct_n=pct_n/(100*_words);
format pct_n percent10.1;
run;
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If below works for you will depend on your actual data.
I've made the assumption that all values are in percent.
data have;
input pct $;
cards;
15%
5
30
10-15%
;
data want(drop=_:);
set have;
length pct_n 8;
pct=compress(pct,' %');
_words=countw(pct,'-');
do _i=1 to _words;
pct_n=sum(pct_n,input(scan(pct,_i,'-'),best32.));
end;
pct_n=pct_n/(100*_words);
format pct_n percent10.1;
run;