BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I need help in my sql code.  Some one helped the code. It worked but i have one more condition that i need to add.

 

I am getting output i need for all   where "var"   in  a,b,c,d,e,f.

 

But var=g   where i included a      "when value lt 1 then 0"     Please suggest. Thank you

Output needed for    var =g

var value prec

g     0.5  0

g     10   0

output getting

var value prec

g     0.5  0

g     10   1

 

data have;
input var $ value;
datalines;
a 100.01
a 110.003
a 100
b 1.1
b 2
c 5.000002
c 6.01
c 4
d 2
d 5
d 1120
e .
e 100
e 10.02
f .
f 10
g 0.5
g 10
;
proc sql;
create table want as
select 
    *,
    case when value =. then .
         when value lt 1 then 0 
        else max(lengthn(scan(put(value, best32.), 2, "."))) end as prec
from have
group by var;
quit;
2 REPLIES 2
yabwon
Onyx | Level 15

Hi,

maybe this:

proc sql;
create table want as
select 
    var,
    value format best32.,
    case when value = . then .
         when value < 1 then 0 
         else max(case when value < 1 then 0
             else lengthn(scan(put(value, best32.), 2, ".")) end) 
         end as prec        
from have
group by var;
quit;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



mklangley
Lapis Lazuli | Level 10

What exactly are you trying to do with this code? Are you sure your results for a, b, c, d, e, and f are what you expect?

Is prec supposed to be the precision of value? (If so, how do you get prec = 6 for value = 4?)

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 354 views
  • 1 like
  • 3 in conversation