Recently in the SAS Community Library: In the second in a series of posts on the SAS 9 Content Assessment reports, SAS' @GerryNelson introduces you to the SAS 9 Application Usage report. You'll learn what information the report provides, what conclusions can be drawn from the information, and what likely actions you would take after reviewing the report.
Hi everybody, I have a question about designing a DCE. I have 2 unlabeled alternatives (Alt1 and Alt2) and also a no-choice option. I have 4 attributes (X1, X2, X3, X4) with their levels mentioned below: X1: %5 %10 %15 %20 X2: 0=no 1=yes X3: 0=no 1=yes X4: 30 40 50 60 Based on what I read, I created this orthogonal design. Here is the design; %mktruns(4 2 2 4 4 2 2 4) /* factor level list for all attrs and alts */
%mktex(4 2 2 4 4 2 2 4, /* factor level list for all attrs and alts */
n=64, /* number of choice sets */
seed=17) /* random number seed
%mktblock(data=randomized, /* block randomized design */
nblocks=2, /* create 2 blocks of 32 choice sets */
out=blocked, /* output data set for blocked design */
seed=17) /* random number seed */
data key;
input
Brand $ Knd $ Omg $ Mrk $ Price $; datalines;
Alt1 x1 x2 x3 x4
Alt2 x5 x6 x7 x8
None . . . . .
;
%mktroll(design=blocked, /* make choice design from blocked */
/* linear arrangement from %mktblock */
key=key, /* use rules in KEY data set */
alt=brand, /* alternative name variable is Place */
out=work.food64, /* permanent data set for results */
keep=block) /* keep the blocking variable */
proc format;
value knd 1 = ’%5’ 2 = ’%10’ 3 = ’%15’ 4 = ’%20’ . = ’ ’;
value omg 1 = ’no’ 2 = ’yes’ . = ’ ’;
value mrk 1 = ’no’ 2 = ’yes’ . = ’ ’;
value price 1 = $30 2 = $40 3 = $50 4 = $60 . = ’ ’;
run;
data work.food64;
set work.food64;
format knd knd. omg omg. mrk mrk. price price.;
run;
proc print data=work.food64(obs=192);
by set; id set;
run; When I examined the generated choice sets, I noticed that in some choice sets, every level was the same except for price. For example, the choice set shown below; What can I do to avoid these choice sets? Thank you so much!
... View more
I am trying to take stock of the extent of missingness over multiple years for multiple subsets of variables. So, I've been working on a macro to automate this. There is a problem in my code (in blue) where I try to generate a variable that is a count of missings for each row. The counts in the resulting variable are incorrect. %LET STEST2 = VAR1 VAR2 VAR3... VAR35 /* &SVARS */
/* LISTN (LISTNAME) = TEST */
%MACRO PERCENTCOMPLETE(YEARS,SVARS,LISTN);
%LET COUNT = %SYSFUNC(COUNTW(&YEARS));
%DO I = 1 %TO &COUNT;
%LET YEAR = %SCAN(&YEARS, &I);
%PUT YEAR = &YEAR LISTN = &LISTN SVARS = &SVARS;
DATA WORK.SVARS&YEAR&LISTN;
SET S2&YEAR;
KEEP &SVARS ;
RUN ;
DATA WORK.MODELVARS&YEAR&LISTN;
SET SVARS&YEAR&LISTN;
ARRAY VARS {*} _NUMERIC_ ;
NUM_VAR&YEAR&LISTN = DIM(VARS);
RUN ;
DATA PERCOM&YEAR&LISTN ;
SET MODELVARS&YEAR&LISTN ;
MISSCOUNT&YEAR&LISTN = CMISS(OF _ALL_); MISSPER&YEAR&LISTN = MISSCOUNT&YEAR&LISTN/NUM_VAR&YEAR&LISTN;
LENGTH COMOBS&YEAR&LISTN 3. ;
COMOBS&YEAR&LISTN = 0 ;
IF MISSCOUNT&YEAR&LISTN = 0 THEN COMOBS&YEAR&LISTN = 1 ;
LENGTH EMPOBS&YEAR&LISTN 3.;
EMPOBS&YEAR&LISTN = 0 ;
IF MISSPER&YEAR&LISTN = 1 THEN EMPOBS&YEAR&LISTN = 1 ;
RUN ;
%END;
%MEND ;
%PERCENTCOMPLETE(2017 2018 2019 2020 2021 2022 2023, &STEST2, TEST); I know that I can use: MISSCOUNT&YEAR&LISTN = CMISS(OF VAR1 -- VAR35); However, I want to be able to run this for different subsets that have different starting and ending variables. At this point, I could have just copied and pasted the code 800 times with that small edit, but I am being stubborn. All suggestions very appreciated!
... View more
Hi everybody,
I am trying to simulate Poisson data but not sure if I am doing it correctly.
I know that in a given population, an event occurs at a rate of 1.2 per year.
If I would like to simulate 1000 set of data each containing 50 patients, is this how the code should be written?
Thanks!
data Poisson; call streaminit(4321); lambda = 0.8;
do SimID = 1 to 1000; do i = 1 to 50; x = rand("Poisson", lambda); output; end; end; run;
... View more
Hello Community, I remember being able to map variable value into LINE statement text in the past, but cannot figure out it now. I believe there is an elementary item that I'm missing (which is unfamiliar to me). Currently, to map a variable value into the LINE I keep hardcoding, eg. using IF/ELSE (see below #1). Could anyone fix #2 and explain how to avoid hardcoding part? Many thanks!
data have;
input visitnum visit $;
if visit eq 'Screen' then do score= 1 to 5; output; end;
else do score= 1 to 6; output; end;
cards;
1 Screen
2 Week_1
3 Week_2
4 Week_3
;
run;
proc format;
value score 1= 'Very severe'
2= 'Severe'
3= 'Moderate'
4= 'Mild'
5= 'Minimal'
6= 'No pain';
run;
/* 1. Current coding */
proc report data=have;
column visitnum visit score;
define visitnum/order noprint;
define visit/ noprint;
define score/'Response Category' format=score. style(column)={just=l} display;
compute before visitnum/style={just=l};
line @1 text $40.;
length text $40;
if visitnum=1 then text='Screen';
else if visitnum=2 then text='Week_1';
else if visitnum=3 then text='Week_2';
else if visitnum=4 then text='Week_3';
endcomp;
run;
/* 2. Wanted coding - needs to be fixed to get the same result as #1*/
proc report data=have;
column visitnum visit score;
define visitnum/order noprint;
define visit/ noprint;
define score/'Response Category' format=score. style(column)={just=l} display;
compute before visitnum/style={just=l};
line @1 text $40.;
length text $40;
text=visit;
endcomp;
run;
... View more
Good evening to the community! I have the following issue. I have a bunch of the following CSV files that contain customer details for a bank: Customer_details_202101 , customer_details_202102 ,customer_details_202101, customer_details_202111 Where the first 4 digits in the 6-digit number at the end of the names is the year (2021 here) and the last 2 are the month, i.e. I have data from January to November 2021. I want to create a macro program that creates a dataset named CUSTOMER_DETAILS_HIST that includes all the customer details from 01/01/1950 to 31/12/2100. To do so, I have created the macro as follows: %macro creation;
%do i=195001 %to 210012;
filename raw "C:\Customer_details_&i";
data customer_details_history;
infile raw dsd firstobs=2;
input variables;
run;
%end;
%mend creation;
%creation; However, the code above will create a dataset for 2021/01, but then it will replace the dataset with the data from 2021/02. What I want to do is append, not replace. I was thinking of creating another %do block inside the loop, telling SAS: "Create the dataset for the first month that is available. Then, exit the loop." (so that I can perform the appending on a separate stage). How can I tell SAS to exit the loop, but not the session? (so, not %ABORT). I know that in a DATA step DO loop there is the LEAVE statement. Is there anything I can use in a macro? Thank you in advance!
... View more
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
The SAS Customer Recognition Awards are open for nominations until Jan 31. Winners get a full trip to SAS Innovate (May 6-9) in Orlando, FL! See the contest description for rules and how to apply.