SAS Visual Analytics Tips & Tricks Series: Working with URL links
Recent Library Articles
Recently in the SAS Community Library: In a video tutorial, SAS' @KalleM share three use cases that reveal how URL links can be used and created in SAS Visual Analytics.
I have a data set where a "count" variable means there are X numbers of individuals with the preceding characteristics in that observation. See below as an example. In the first observation, 3 means there are three 24 year-old males who scored 100. data sample;
input age score sex$ count;
datalines;
24 100 M 3
25 95 F 2
25 97 M 2
20 86 M 3
30 100 F 2
;
RUN; Let's say I wanted to do a proc freq of sex * score. PROC FREQ data=sample;
TABLES sex*score;
run; Is there a way to call out the actual number of each sex achieving each score by using the "count" value for each observation? My code above counts only one sex per row, obviously.
... View more
SAS Viya on Microsoft Azure includes extensive online documentation, a learning portal with self-paced training courses, and access to this active SAS Community to answer your questions.
If you have questions or support needs as you use SAS Viya on Microsoft Azure, we invite you to post your question to this support forum. SAS experts are ready to reply with guidance to help you to learn and to help you to troubleshoot any challenges you encounter.
Essential resources
SAS documentation for SAS Viya on Microsoft Azure
Community support forum for SAS Viya on Microsoft Azure
Learning Center for SAS Viya for Microsoft Azure (linked from within the product, requires activation)
License terms (including policies for basic support)
... View more
Hi guys,
suppose to have the following:
data DB;
input ID :$20. Event Index;
cards;
0001 1 0
0001 0 1
0002 1 1
0002 0 0
0003 1 0
0003 0 2
0003 0 0
0003 0 0
0003 0 0
run;
Is there a way to get the following?
data DB1;
input ID :$20. Event Index;
cards;
0001 1 1
0001 0 0
0002 1 1
0002 0 0
0003 1 2
0003 0 0
0003 0 0
0003 0 0
0003 0 0
run;
In other words the value of Index should be moved where event = 1 when it is already not there. Only moved. No other calculation is required.
Thank you in advance
... View more
I want to know what percent of clients had more than one stay for each client. I am trying to calculate percent of the group total where the group total is the distinct count of clients in the group (clinic). The code below is calculating percent of the grand total for each row. How can I fix this?
Thank you!
data have;
input client_id$ Span_Begin :DATE9. Span_End :DATE9. clinic$ stay$ cost R$ year$ clinic_type$;
format Span_Begin MMDDYY10. Span_End MMDDYY10. ;
datalines;
A 17Nov2022 04Jan2023 8 1 0 1 2023 1
B 01Jul2022 29Jul2022 12 1 2746 1 2023 3
B 21Nov2022 04Apr2023 12 2 1373 1 2023 3
C 01Jul2022 07Jul2022 8 1 2403 1 2023 3
C 12Jul2022 25Jul2022 6 2 343 1 2023 3
C 26Aug2022 15May2023 10 3 687 1 2023 3
D 01Jul2022 12Jul2022 10 1 5479 0 2023 2
E 01Jul2022 23Mar2023 9 1 159000 1 2023 3
F 22Nov2022 19Mar2023 8 1 6522 1 2023 3
G 26Aug2022 15May2023 12 1 687 1 2023 3
H 01Oct2022 10Apr2023 6 1 5479 1 2023 3
I 30Dec2022 19Jan2023 5 1 8675 1 2023 3
J 01Jul2022 01Nov2022 3 1 4566 1 2023 3
K 11Nov2022 10Jan2023 3 2 10044 1 2023 3
L 01Jul2022 15Jul2022 3 1 9588 1 2023 3
L 26Jul2022 17Aug2022 12 2 2060 0 2023 3
L 23Sep2022 19Feb2023 12 3 5149 1 2023 3
O 20Sep2022 20Feb2023 5 1 5022 1 2023 3
P 01Jul2022 02Aug2022 5 1 913 1 2023 1
Q 06Jul2022 01Sep2022 8 1 343 1 2023 3
R 01Jul2022 01Sep2022 1 1 457 1 2023 3
S 01Jul2022 24Oct2022 2 1 10957 1 2023 3
T 01Jul2022 04Dec2022 2 1 1826 1 2023 3
U 28Aug2022 18Sep2022 8 1 6179 1 2023 3
V 19Dec2022 31May2023 7 2 10501 1 2023 3
W 08Jun2023 18Jun2023 7 3 5022 1 2023 3
X 01Jul2022 10Jul2022 8 1 3433 0 2023 3
Y 04Aug2022 17Nov2022 10 2 7305 1 2023 3
Z 13Oct2022 07Nov2022 8 1 2403 1 2023 3
Z 09Feb2023 30Jun2023 12 2 5149 1 2023 3
AA 08Sep2022 04Oct2022 8 1 2746 1 2023 3
BB 01Jul2022 26Apr2023 2 1 10501 1 2023 3
CC 09Aug2022 19Jun2023 12 1 1373 1 2023 3
DD 01Jul2022 21Aug2022 10 1 9588 1 2023 3
DD 17Oct2022 13Jun2023 11 2 5935 1 2023 3
EE 01Jul2022 15Jul2022 5 1 3196 1 2023 3
EE 26Jul2022 17Aug2022 5 2 7305 1 2023 3
EE 23Sep2022 19Feb2023 4 3 13697 1 2023 3
;;;
run;
*** distinct client count per clinic****;
proc sql;
select clinic, count(distinct client_id) as pct_of from have
where clinic_type eq '3' and year eq '2023' and R eq '1' and cost>0
group by clinic;
run;
Title1 “Percent of clients with >1 stay”;
proc sql ;
select distinct clinic, count( distinct client_id) as Clients, calculated clients / (select count(distinct client_id) from have
where clinic_type eq '3' and year eq '2023' and R eq '1' and cost>0) as pct format=percent8.1
from have
where clinic_type eq '3' and year eq '2023' and R eq '1' and cost>0 and Stay ne '1'
group clinic
union all
select "Total", count( distinct client_id) as Total from have
where clinic_type eq '3' and year eq '2023' and R eq '1' and cost>0 and Stay ne '1';
quit;
I'm getting this:
I want this:
... View more
Morning all, I'm using Proc IML's NLPQN to solve a minimization problem with 9 nonlinear nonequality constraints. The choice variable is a vector with 16,000+ nonnegative entries. The problem is that the NLPQN call returns the " Unable to allocate sufficient memory" error. I've run structurally similar problems before with no issues, so I think the dimensionality is what's chocking the program here. I'm running SAS version 9.04.01M6P111518 in a machine with Nvidia 4090 GPU and an Intel Core i9-13900KF CPU with DDR5 RAM just shy of 60GB of RAM. My questions are: (i) is this a computationally feasible problem? (ii) I'm relatively new to SAS nonlinear programming, so can you give me some light on if and where the code can be more efficient? Thanks in advance, this community has a been a great resource since I started my SAS journey. proc iml;
/* Store the status-quo param as a vector */
use work.param;
read all var {lparam} into pre_param0;
param0 = exp(pre_param0);
/* Storing the number of employees */
dim = nrow(param0);
/* Retrieve the coefficient columns as vectors */
use work.olsmat;
read all var {g1} into g1;
read all var {g2} into g2;
read all var {g3} into g3;
read all var {g4} into g4;
read all var {g5} into g5;
read all var {g2_g1} into g2_g1;
read all var {g4_g1} into g4_g1;
read all var {g3_g1} into g3_g1;
read all var {g5_g1} into g5_g1;
/* Retrieve status quo tots */
tot0 = (g1` // g2` // g3` // g4` // g5` // g2_g1` // g4_g1` // g3_g1` // g5_g1`)*log(param0);
print tot0;
/* Declare initial guess */
z0 = j(1,dim,0);
/* Defining the objective function */
start rev(x);
S = sum(x);
return(S);
finish rev;
/* Declaring the gradient of the obj function */
start gradient(x) global(dim);
g = j(1,dim,1);
return(g);
finish gradient;
/* Defining lower and upper bounds */
noupper = j(dim,1,.);
lower = j(dim,1,0);
bounds_noupper = lower` // noupper`;
/* Defining the nonlinear constraints */
start constr(x) global(param0, g1, g2, g3, g4, g5, g2_g1, g4_g1, g3_g1, g5_g1);
prov = log(param0`+x);
matc = j(9,1,.);
matc[1,1] = prov*g1;
matc[2,1] = prov*g2;
matc[3,1] = prov*g3;
matc[4,1] = prov*g4;
matc[5,1] = prov*g5;
matc[6,1] = prov*g2_g1;
matc[7,1] = prov*g3_g1;
matc[8,1] = prov*g4_g1;
matc[9,1] = prov*g5_g1;
return(matc);
finish constr;
/* Declaring the Jacobian of the constraint */
start jacobian(x) global(param0, g1, g2, g3, g4, g5, g2_g1, g4_g1, g3_g1, g5_g1);
prov = param0`+x;
jac1 = g1`/prov;
jac2 = g2`/prov;
jac3 = g3`/prov;
jac4 = g4`/prov;
jac5 = g5`/prov;
jac6 = g2_g1`/prov;
jac7 = g4_g1`/prov;
jac8 = g3_g1`/prov;
jac9 = g5_g1`/prov;
return(jac1 // jac2 // jac3 // jac4 // jac5 // jac6 // jac7 // jac8 // jac9);
finish jacobian;
/* Defining Problem Options */
optn= j(1,11,.);
optn[2]=1; /* output printing options */
optn[10]=3; /* number of nonlinear constraints */
optn[11]=0; /* number of equality constraints */
/* Define Termination Criteria */
terc = j(1,13,.);
terc[1] = 10000;
terc[2] = 25000;
terc[4] = 1E-6;
terc[6] = 1E-6;
terc[8] = 1E-6;
/* Call the optimization method */
call nlpqn(rc, xres, "rev", z0, optn, bounds_noupper) tc=terc nlc="constr" grd="gradient" jacnlc="jacobian";
print rc;
optimum = xres`;
tot1 = (g1` // g2` // g3` // g4` // g5` // g2_g1` // g4_g1` // g3_g1` // g5_g1`)*log(param0+optimum);
print tot1;
create optout from optimum[colname="rem"];
append from optimum;
close optout;
qui t;
... View more