Using The SAS VS Code Extension to Check Prime Distribution
Recent Library Articles
Recently in the SAS Community Library: @RyanKing showcases features in the SAS Visual Studio Code extension, including data exploration using SAS, SQL and Python in one SAS notebook file.
How can I change this macro to create all the variables in one data set? I want to do this for multiple varibles using the macro but it keeps overwriting itself and keeping the last flag that was created by the macro. Thank you!
%MACRO FLAG(VAR1,VAR2,FLAGNAME); DATA FLAG; SET RULE1; &FLAGNAME=0; DO _N_=1 to countw(&VAR1,',') while(&FLAGNAME=0); word=scan(&VAR1,_N_,','); if word=' ' then continue; if indexw(trim(&VAR2),trim(word),',') then &FLAGNAME=1; end; drop word; run; %MEND FLAG;
%FLAG(Addresses1,Addresses2,First_ADD); %FLAG(Addresses1,Addresses3,Second_ADD);
... View more
Brand new to SAS. I'm doing something that I expect is relatively easy, but I'm struggling to get it right. The requirement is basic - I'm reading in a long file with many rows, if a record matches a criteria I want it to be shipped to a different "bypass" file that I'll work on in a later process, but it should be removed from the original read-in file. Environment is zOS - input file is defined and passed in via JCL (all working). I get the following errors if I remove my actual logic - if I leave the FILENAME statement in without referencing it there's no errors. ERROR: Invalid logical name. ERROR: Error in the FILENAME statement. ERROR: Invalid file, BYPASS_FILE. FILENAME BYPASS_FILE BYPASS1;
/***********************************************************/
/* READ FILE */
/***********************************************************/
DATA DATAIN;
INFILE DATAIN;
INPUT
@ 00001 RECORD_NUMBER $CHAR8.
@ 01769 COMPONENT_STATUS $CHAR1.
;
/*******************************************************************/
/* CREATE BYPASS FILE - USED TO STORE RECORDS WHICH HAVE AN */
/* INACTIVE COMPONENT: COMPONENT_STATUS = I */
/*******************************************************************/
IF COMPONENT_STATUS = 'I' THEN DO;
FILE BYPASS_FILE;
PUT;
DELETE;
END;
... View more
he purpose of this blog is to learn how to use the sasviya.ml and sklearn Python packages in SAS Viya Workbench to build and evaluate machine learning models. SAS Viya Workbench is a new SAS programming environment that supports the use of both the SAS and Python languages. The Workbench environment is designed to support native Python programming, and SAS has released a proprietary Python package named sasviya.ml that contains optimized SAS machine learning algorithms designed to run in SAS Viya Workbench. Of course, SAS Viya Workbench can also be used to execute SAS procedures, but this blog will focus on the Python functionality.
... View more
Hi Everyone,
I am getting below error message when trying to run below code with ENCODING=WLATIN1 from SAS Studio. Can you please suggest on it.
Note : The same code is running fine with ENCODING=UTF-8
DATA T1; var1="aábcčdď"; run;
... View more
Dear All, I am writing a custom objective function in the PROC IML environment where I want to estimate 56 parameters. Of these, I have 51 are week fixed effects and the rest 5 are parameters of interest. I want to conduct the estimation on a dataset with 4,037,641 rows. The code below works but takes very long; no output in over 16 hours. However, for a sub-sample of 23,809 rows, the code executes in 4:45.73 real-time and 1:38.68 CPU time. I would like your suggestions on ways to optimize this code. Thank you in advance. Best, Rakesh proc iml;
/************************/
/*Read relevant variables from the data into a matrix X*/
varNames = {"seq" "position" "usage_upto" "lag_mean_usage_after_p" "credits_left" "sl_fixed_effect" "pos_fixed_effect" "max_pos" "wk" "choice_p" "chosen" "week_fe_scroll"};
use scroll;
read all var varNames into x;
close scroll;
/************************/
b = uniqueby(x[,1],1)`; /*starting points in each session*/
u = unique(x[,1]);
b = b ||(nrow(x[,1])+1); /* trick: append (n+1) to end of b for taking care of the last session*/
param = {3.354 -0.097 -2.538 0.146 0.002 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}; /*set initial parameter values for models with CHOSEN VARIABLE*/
start LogLik(param) global(x,b);
s = j(1, ncol(b)-1,.); /*Create an empty matrix to store probability of each session*/
do i = 1 to ncol(b)-1;
idx = b[1,i]:(b[1,i+1]-1);
/*Extract unique session Ids in vector u*/
pos = x[idx,2]`;
sess_usage_upto = x[idx,3]`;
lag_use = x[idx,4]`;
sess_credits = max(x[idx,5]`);
sl_fe_scroll = max(x[idx,6]`);
sl_pos_scroll = max(x[idx,7]`);
max_pos = max(max(x[idx,8]`),3);
wk = max(x[idx,9]`);
choice_p = x[idx,10]`;
chosen = x[idx,11]`;
wk_fe_scroll = x[idx,12]`;
/************************/
/*Create a vector for transaction probability at all positions. Create the probability of observing the choice at each position (choice_mult)*/
choice_mult = (choice_p##chosen) # ((1-choice_p)##(1-chosen));
/************************/
/*Create a vector for probability of scrolling further at all positions
The seller always scrolls further from the first two positions*/
if wk = 52 then k = 0; else do; z = wk + 5; k = param[z]; end;
sc = logistic(param[1] + param[2]*pos + param[3]*(sess_usage_upto/pos) + param[4]*lag_use + param[5]*sess_credits + k);
sc[1,1] = 1; sc[1,2] = 1;
choice_mult_sc = choice_mult # sc; /*multiply choice prob and scrolling prob at each position*/
/************************/
/************************/
/*Create a vector for probability of ending at all positions greater then the maximum position
Up to the maximum position, the probability of ending is 0*/
ed = 1 - sc;
ed[1, 1:max_pos-1] = 0;
choice_mult_ed = choice_mult # ed; /*multiply choice prob and scrolling prob at each position*/
/************************/
/************************/
/*Compute the probability of a sample path for all possible end points in a session. Store each probability in a vector called LL*/
lag_prod_sc = lag(cuprod(choice_mult_sc))`;
lag_prod_sc[1,1] = 1;
LL = lag_prod_sc # choice_mult_ed;
if LL < 1/(2**500) then LL = 1/(2**500);
/************************/
s[i] = log(10*sum(LL)); /*Probability of aN OBSERVED session is the sum of all sample paths */
end;
return sum(s);
finish;
/************************/
/*Maximize sum(s)*/
optn = {1, /* 3. find max of function, and */ 2}; /* print moderate amount of output */
con = {. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ,
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .};
call nlpnra(rc, xres, "LogLik", param, optn, con);
/************************/
quit;
... View more