spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » SAS » Page 1
Graphing hazard using SAS when a time-dependent covariate is included
For some reason, PHREG will only plot cumulative hazards. This approach will get you a plot of the baseline hazard function. First use the BASELINE statement in PHREG to get survivor function estimates, like so: proc phreg data = yourdata; model (start, end)*death(0) = ...; baseline out = bl survival = s ... / method = pl; run; Then feed the output dataset into a macro called smooth, w

Categories : Sas

Calculate multiple column percentages
Use SUMMARY to calculate the sum of each column and then join it back on to the original. Calculate your percents then. data input; input Row$ Col1 Col2; datalines; A 10 20 B 20 20 C 20 20 ; run; proc summary data=input; var col1 col2; output out=sum(drop=_type_ _freq_) sum= /autoname; run; data want(drop=col1_sum col2_su

Categories : Sas

SAS date transformation
You're almost there... simply change the outer input() to a put(). data _null_; format yyyymmdd $8.; yyyymmdd = '20141120'; filedate = put(input(yyyymmdd, yymmdd8.), date9.); call symput('filedate', filedate); run; %put &filedate.;

Categories : Sas

SAS 4GL - multiple informats
The trick here is to use the : format modifier to stop SAS trying to read beyond the next delimiter after the % sign. You can also set the lengths of your other variables on the input statement this way: data want; infile cards4 dsd dlm = ';' firstobs = 2; input imie $ nazwisko :$15. wiek $ indeks $ PESEL :$11. kierunek :$15. rok urodziny srednia :PERCENT3. frekwencja ddmmyy8. ; format frekwencja

Categories : Sas

SAS-Macro-exponential function
The below will give you want you're after. %macro expplot(base=, from=, to=, inc=) ; data dset ; base=&base; do xvar=&from to &to by &inc; yvar=base**xvar ; put base= xvar= yvar= ; output ; end ; run ; proc sgplot data=dset ; series x=xvar y=yvar; title "Exponential plot of &base"; run ;

Categories : Sas

SAS drop cloned observation
proc sql; select distinct * from olddata; quit; Sounds like an easy SQL fix. The select distinct option will remove any completely duplicate rows in a dataset if you select all columns.

Categories : Sas

generate random names in SAS
Find a list of names (either make it, or download some - list of Harry Potter characters, list of common first names/baby names, list of common last names, etc.) Produce a dataset like so: Format dataset: Start = ID or other way to identify the real person (first/last name combo) Label = First Name + Last Name selected from list (or do this 2x, one for each) Fmtname = RANDONNAMEF Then read i

Categories : Sas

Using SAS I want to print the 5 rows with the highest value in a certain column
You can use proc sql with the outobs= option, and the appropriate sort order. For example, to get the rows with the top 5 maximum values : proc sql outobs=5 ; create table top5 as select * from mydata order by targetvar descending ; quit ; Obviously, if you've got multiple rows with the same maximum value, you may want to use a different approach.

Categories : Sas

Conditional sum using proc sql
First off, if you're in SAS I would recommend using SAS tools! In this case, either a PROC FREQ or better PROC TABULATE would do this directly, and if you want a dataset you can get that with ODS OUTPUT. ods output table=want; proc tabulate data=have; where absence_type in (10,14,15); class absence_type employee_id; var duration_days; tables employee_id,absence_type*duration_days*sum; run; proc

Categories : Sas

Typically under what circumstances will a SAS Pooled Workspace Server be launched?
SAS Web Report Studio and SAS BI Dashboard (webapplications) uses the Pooled Workspace server. They should be running under a common user (sassrv is default). There will be one running instance even though no-one uses it. You can see the launch properties of the Pooled Workspaceserver in SAS Managent Console, under Server Manager>SASApp>SASApp-Logical Pooled Workspace Server>SASApp-Pooled Workspac

Categories : Sas

SAS proc tabulate outputs column total
Use dtdate9 to format your datetime to date9. You may want multiple class statements since that won't be a preloadformat. Add another all at the end for the Grand Total. proc tabulate data=HAVE missing; class City/order=data preloadfmt; class Date/order=data; format City $Areaformat.; format date dtdate9.; var Index1 Index2; table (Date=''), (Index1={Label="AAA" s=[cellwidth=2in just=c]}*(s

Categories : Sas

Newid() equivalent in BASE SAS
Such identifiers need to be manually configured, according to your needs. A basic approach (assuming your identifier is numeric) may follow along the lines of: /* get previous maximum id and store in macro variable */ proc sql noprint; select max(identifier) into: max_identifier from MainTable; /* generate new identifier starting from previous high value */ data append; retain identifier &am

Categories : Sas

Cobol number format
I have no experience with it, but PROC COPYLIB is a SAS procedure that will read any valid COBOL record layout and produce the following: 1) Generate an equivalent input statement for the processed COBOL record layout. 2) A SAS dataset containing a description of the COBOL record layout. This data set can be used as a data dictionary. 3) COBOL Record Layout Report -- which details the COBOL rec

Categories : Sas

Variable name out of an array value
PROC TRANSPOSE is usually the easiest way to do this. First, make a vertical dataset like so: data vert; array id[5] (1,8,4,12,23); do _i = 1 to dim(id); varname = cats('A_',id[_i]); vvalue = 1; *it is not apparent to me what the value should be in A_12 or whatnot; output; end; run; Then PROC TRANSPOSE makes your desired dataset. proc transpose data=vert out=want; id varna

Categories : Sas

Trying to retain only non missing values (if any) for a particular variable(condition)
Here, what you need is effectively two passes through the data: one to identify id-groups (testA groups) that have a testC row that's useful, and one to grab the first row of those that don't. Two ways immediately present themselves to me, in the data step. PROC SQL could also pretty easily achieve this if you are more comfortable in that. The simplest method is simply to create a dataset of th

Categories : Sas

Monitoring SAS loads into SQL
It's certainly possible, but I'm not sure I'm clear enough on what you want. SAS has a log, which indicates when a load is done and how many rows have been loaded, as well as how long it took. NOTE: The data set WORK.TEST has 10 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds You also

Categories : Sas

How to pull the column name in to the data in SAS
You want to use the vlabel() function since those column headings don't meet standard variable name requirements and I'm assuming they're labels. Below is example code to put in a data step, but you'll have to know the actual variable names for the array declaration and replace date1--date99 with them. array mydates (*) date1--date99; do over mydates; if mydates = 1 then flag = vlabel(mydate

Categories : Sas

Create function of two variables with do loop
try: %macro do_loop; data testdo; set Popn99; %do i = 1 %to 99; AR_&i. = 0.5 * (ADM_&i. + ADM_%eval(&i.+1) ); %end; run; %mend do_loop; %do_loop; Remember that SAS Macro code writes TEXT only. So the following assignment, should it have resolved (which it wouldn't as the "J" macro variable didn't exist), would have assigned a value to a "column". &j.=&i.+1; That

Categories : Sas

Checking to see if each value in one dataset is equal to ANY value in another dataset column
You can use a sql left join to check the variables. You may need to add conditions to either the case statement or where clause: DATA CODES; DO CODE=1 TO 100; OUTPUT; END; RUN; DATA MY_CODES; DO CODE=50 TO 150; OUTPUT; END; RUN; Proc sql; Create Table Check as select a.*, case when a.code=b.code then 1 else 0 end as match from MY_CODES a left join

Categories : Sas

Create a new column in SAS with condition
Assuming that your input table (table1) is sorted by SN, the following code should perform the required action: data newtable (drop=_x); set table1; by SN; if first.SN then _x = 1; if RT = 1 and _x then do; newvar = 1; _x = 0; end; else newvar = 0; run; When the first value of SN is found, a flag _x is set to 1, this basically says 'start checking for RT = 1'. When we find t

Categories : Sas


Recently Add
SAS yyyymmdd to last date of month
Graphing hazard using SAS when a time-dependent covariate is included
Calculate multiple column percentages
SAS date transformation
SAS 4GL - multiple informats
SAS-Macro-exponential function
SAS drop cloned observation
generate random names in SAS
Using SAS I want to print the 5 rows with the highest value in a certain column
Conditional sum using proc sql
Typically under what circumstances will a SAS Pooled Workspace Server be launched?
SAS proc tabulate outputs column total
Newid() equivalent in BASE SAS
Cobol number format
Variable name out of an array value
Trying to retain only non missing values (if any) for a particular variable(condition)
Monitoring SAS loads into SQL
How to pull the column name in to the data in SAS
Create function of two variables with do loop
Checking to see if each value in one dataset is equal to ANY value in another dataset column
Create a new column in SAS with condition
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.