Please help me with error: Error: The connection could not be established to a SAS Workspace Server named 'Local' running on port on host 'localhost'. Please verify the following: - The correct hostname and port number were specified. - If a firewall is present, it is correctly configured to allow this access. - An object spawner has been started on the server. - The SETINIT on the server is not expired. Please contact your SAS Administrator if the problem persists. Server response: Server execution failed
... View more
I write one macro which works fine to split data into 2-subgroups.
Logic is 1) sort by target var 2) based on weight/wt, split into 2 subgroups.
BUT how to split into N-Subgroups with N as a parameter, say N=3 or 7?!
%macro bisect(ds, byvar, cutvar, note);
proc sort data=&ds.; by &byvar.; run;quit;
data &ds.;
set &ds.;
retain wt_sum;
wt_sum=coalesce(wt_sum,0)+&cutvar.;
run;quit;
data &ds.(drop=wt_sum);
set &ds.;
if wt_sum<=50 then ¬e.=1;
else ¬e.=0;
run;quit;
%mend;
... View more
I've been looking for a good, efficient method to create "Table 1", which has a more or less standard format in research journals:
Variable Name
Category 1
Category 2
P-value
Variable 1
1
N(%)
N(%)
Chi-sq or Fisher's
2
N(%)
N(%)
3
N(%)
N(%)
Variable 2
Mean (SD)
Mean (SD)
t-test
Median (IQR)
Median (IQR)
I found this PDF paper. It seems to work pretty well, but I'm having 2 issues. The first is that the chi-square results are saved into a file and then merged into the main file. But the value of the "variable" variable is the var label in 1 file and the var name in the other, so they don't merge.
The second issue is that Proc Report does not produce a table and instead gives me this: NOTE: Groups are not created because the usage of levels is DISPLAY. To avoid this note, change all GROUP variables to ORDER variables.
WARNING: A GROUP, ORDER, or ACROSS variable is missing on every observation.
data have;
infile datalines dsd dlm=',' truncover;
input DEM_AGE DEM_SEX cohort_flag TM_group;
datalines;
3,1,1,0
2,1,1,1
3,2,1,1
3,2,1,1
3,2,1,0
2,2,1,1
2,1,1,1
3,1,1,1
2,1,1,1
3,2,1,0
2,1,1,0
2,2,1,1
3,2,1,0
2,2,0,
3,2,1,1
3,2,1,1
3,1,1,0
3,2,1,0
2,1,1,0
3,1,1,1
3,2,1,1
3,2,1,0
3,2,1,1
3,2,1,1
3,2,1,1
; RUN;
/*Load formats from existing file in temp folder*/
options fmtsearch=(temp.formats);
/*DEM_SEX sex 1 Male 2 Female*/
/*DEM_AGE AGE2GRP 1:Age Group <65 2:Age Group [65,75) 3:Age Group >=75*/
/*TM_group yesno 1 Yes 2 No*/
/*Generate descriptive statistics*/
proc means data = temp.have noprint n sum mean;
class DEM_AGE DEM_SEX;
var TM_group /*MA_group*/;
ways 1;
output out = temp.expl_PreTable n =
sum =
mean = / autoname;
WHERE cohort_flag = 1;
run;
/*Format descriptive stats*/
data temp.expl_Table (keep = variable levels TM_group_N TM_group_sum
TM_group_mean pct ExpPct indexvar); set temp.expl_PreTable;
length variable $ 20; /* These four variables */;
length levels $ 20; /* will describe the first */;
length pct $ 8; /* four columns of the table */;
length ExpPct $ 15;
if DEM_AGE ne . then do; /*Building "variable" and "Levels" columns for "DEM_AGE"*/;
variable = 'Age category';
levels = put(DEM_AGE, age2grp.);
IndexVar = 1; /*This index is included just in case the order of data presentation needs to be changed*/;
end;
if DEM_SEX ne . then do; /*Building "variable" and "Levels" columns for "DEM_SEX"*/;
variable = 'Sex';
levels = put(DEM_SEX,sex.);
IndexVar = 2;
end;
pct = put(TM_group_mean*100,4.1); /*Calculate % exposed */;
ExpPct = compress(put(TM_group_sum,comma4.),' ')
||' '||'('||compress(pct,' ')||')'; /*creating data in the form of "count (%)" */;
run;
/*Run chi-square significance tests and use ODS to create a dataset of these results*/
ods trace on;
ods output chisq = temp.expl_ChiData;
proc freq data = temp.have;
table TM_group*DEM_AGE / chisq;
table TM_group*DEM_SEX / chisq;
WHERE cohort_flag = 1;
run;
ods trace off;
/*Rearrange chi-square dataset so it can be merged with descriptive stats table*/
data temp.expl_ChiData2 (keep = variable prob);
set temp.expl_ChiData (where = (statistic = 'Chi-Square'));
length variable $ 20;
variable = scan(table,-1,' '); /* Returns the last word in a character value from the "table" variable*/
run;
/*Sort both tables so they will merge*/
PROC SORT data=temp.expl_Table OUT=temp.expl_Table_sort; BY variable; RUN;
PROC SORT data=temp.expl_ChiData2 OUT=temp.expl_ChiData2_sort; BY variable; RUN;
/**************MERGE DOES NOT WORK BECAUSE The value of the "variable" variable is the var label in 1 file
and the var name in the other. DUE TO THE 'IF a' STATEMENT, NOTHING FROM THE CHIDATA2 FILE IS MERGED IN****/
/*Merge descriptive stats table with chi-square table*/
DATA temp.expl_TableData;
MERGE temp.expl_Table_sort (in = a) temp.expl_ChiData2_sort (in = b);
BY variable;
IF a;
RUN;
/*Use PROC REPORT to create final output table*/
proc report data = temp.expl_TableData nowd;
column variable levels TM_group_N ExpPct prob;
define variable / "Variable" group format = $variable.;
define levels / " " ;
define TM_group_N / "TM" /*format = comma5.*/;
define ExpPct / "TM Group/n (%)";
define prob / "p-value" group format = pvalue6.4;
Title "Table 1. Descriptive characteristics of individuals in the sample";
RUN;
... View more
NEW VIYA FEATURES
Check out these new features and what they mean for you.
Product: SAS Model Studio
New feature: Calculate TreeSHAP values
Description: Enhancement to the Score Data Node: New property Calculate TreeSHAP values under Output Data. This can calculate the SHAP values for Forest or Gradient Boosting models for all observations. Learn more.
Product: SAS Intelligent Decisioning
New feature: Add, manage and report on tags
Description: You can use the tag management category view to create and manage the list of tags that can be associated with SAS Intelligent Decisioning objects. Learn more.
Product: SAS Enterprise Guide
New feature: Enterprise Guide integration with SAS Viya 4
Description: SAS Enterprise Guide version 8.4 can now connect to SAS Viya 4. Learn more.
SPOTLIGHT USE CASE
Enterprise Guide integration with SAS Viya 4
All current SAS Enterprise Guide users can now run their SAS programs on SAS Viya 4. In addition to not having to recode, this allows users to benefit from a modern cloud-based platform to create new projects and gain cloud computing efficiencies. By distributing certain processing onto the SAS Cloud Analytics Services (CAS), SAS Enterprise Guide users can now take full advantage of the scalability and state-of-the-art analytics in Viya. Tune in Tuesday, May 7 at 10 a.m. ET to learn more about SAS Enterprise Guide integration with SAS Viya 4 in our Ask the Expert webinar.
TIP OF THE MONTH
Brought to you by David Weik Senior Pre-Sales Solutions Architect, SAS
I'm sure you are familiar with keyboard shortcuts in SAS Studio. Using F3 to run your SAS code has been around forever and I sometimes forget that we even have a run button. But did you know that there are actually many more keyboard shortcuts available in SAS Studio? The shortcuts available are also not just related to the code editor, but also for general navigation around SAS Studio and of course there is a shortcut to see all of the shortcuts (CTRL+F9).
You can also remap and assign additional shortcuts via the Options (1) > Manage keyboard shortcuts (2). Here is my favority funcationality that doesn't have a default keyboard shortcut assigned: Display Syntax Help (without autocomplete). You can search for it or find it under SAS - Coding section. I assigned it the keyboard combination CTRL+ALT+A, hitting that while on any SAS keyword brings up its Syntax Help pop up.
... View more
Hi, I think it would be beneficial to have Generation Data group like dataset in SAS similar to the format used in Mainframe. Generation Data Groups (GDGs) are group of datasets related to each other by a common name. The common name is referred as GDG base and each dataset associated with the base is called a GDG version. You can set the limit of the related files(generations). We can easily keep track of all generation of data sets. Any particular generation can be referred easily. We use lot of datasets which regenerates daily , monthly , yearly etc.. Consider I need to create daily transaction data for the month of May. If Generation Data Group is available, I would define the base like "Tran_May2024". Then I would just create dataset daily in the below way. Data Tran_May2024(+1); -- This will create the next available version. set work_tran_table; run; If need to point current or earlier version i would use the dataset below. Tran_May2024(0) - Latest Version Tran_May2024(-1) - Previous Version Tran_May2024(-2) - 2 versions back If I need the whole month data , i just refer the base Data work_tran_may; set Tran_May2024; --This would all the version available in the base run; you can have options like below LIMIT – To limit the maximum number of generations. NOEMPTY – Uncatalog only the oldest generation in GDG when the limit is reached. EMPTY – Uncatalog all the generations when a limit is reached. SCRATCH -Physically delete the dataset(generation) which is uncataloged. NOSCRATCH – Don’t Physically delete the dataset(generation) which is uncataloged. This would help a lot when we create lot of datasets which are created in a repeatable fashion. Thank Ravi
... View more