w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » SAS » Page 1
SAS: How to assign the first value with a higher rank in a group to the entire group
It isn't clear what rule you want to use if all the Rating values have rank 0. However, the following is pretty close to what you want. It uses a double DOW-loop to calculate a rolling max within each ID by-group and then attach it to every record in that by-group. This means you have to read the input dataset twice, but you avoid producing an intermediate dataset. The example data you've posted

Categories : Sas

SAS - Need to make the filepath used in an INFILE statement dynamic
The most basic version of your statement would be: INFILE "G:FinanceRawDataFilename_%sysfunc(today(),yymmddn8.).txt"; To explain fully: %sysfunc is a macro function in SAS which allows you to use data-step functions in open code, it takes one (optionally two) arguments: The first argument of %sysfunc is the data-step function in question, in this case we want the value of TODAY(), so that is

Categories : Sas

WARNING: Argument 2 to function PUTC referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range
This worked for me in the end: proc format; value myvar 1 = "One" 2 = "Two" 3 = "Three" 4 = "Four"; run; %let i = 1; %let dvar = %sysfunc(putn(&i, myvar.)); %put &dvar; Thanks

Categories : Sas

Keep SAS processing after finding errors
You could evaluate the existence of a dataset using the EXIST() function and make the execution of the append conditional on the outcome. http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000210903.htm

Categories : Sas

Create a sequence of new column names
Probably, something like this would do the job %macro rename2(oldvarlist, newPrefix); %let k=1; %let old = %scan(&oldvarlist, &k); %do %while(("&old" NE "")); rename &old = &newPrefix.&k.; %let k = %eval(&k + 1); %let old = %scan(&oldvarlist, &k); %end; %mend;

Categories : Sas

SAS "successfully assigned from logical server" vs "successfully assigned as follows"
Assuming that you found the two lines right next to each other: The first line is telling you that SAS encountered no problems trying to assign the libref TESTLIB. If you tried to assign a libref to a non-existent folder / server, or you didn't have the necessary access (etc...) you'd get an error message instead of this line. The second line is telling you a bit more about the libref that was a

Categories : Sas

proc tabulate output not in alphabetical order
The easiest answer depends on how the order is derived. You have some ordering options on the class variable, such as order=data, which may give you the desired result if the data is stored in that order. This can be tricky, but sometimes is a simple method to get to that result. Second, you have a couple of options related to formats. If the data can be stored as a formatted numeric, where B

Categories : Sas

Fill in missing values with mode in SAS
Given no code was provided, I'll give you some rough directions to get you started, but put it on you to determine any specifics. First, lets create a month column for the data and then calculate the modes for each key for each month. Additionally, lets put this new data in its own dataset. data temp; set original_data; month = month(date); run; proc univariate data=temp modes; var val

Categories : Sas

In PROC LOGISTIC which value of the parameter is modelled?
If your data are not sorted you can specify the order of your outcome variable right after calling PROC LOGISTIC. I don't have the data, but assuming that ooX is a binary outcome variable with levels 0 and 1, the model will default to modeling ooX = 0 unless you specify that you want it in descending order. PROC LOGISTIC data = TTTT descending; /* will model ooX = 1 */ class ooX Y1 Y2 Y3 Y4; /*

Categories : Sas

Estimating a response value based on known parameters
2 ways: Append the data you want into the data set you're going to use to get estimates but leave the y value blank. Grab the estimates using the output statement from proc reg. Use Proc Score http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_score_sect018.htm

Categories : Sas

SAS data manipulation
You can use PROC TRANSPOSE DATA=TRAIL1 OUT=TTRAIl1(DROP=_NAME_) PREFIX=COL; VAR app; BY id; RUN; %LET NCOLS = 3; *you can get this from VTABLE DATA RES(DROP=i COL1 - COL&NCOLS.); SET TTRAIl1; LENGTH RES $256; ARRAY COLS{*} COL1 - COL&NCOLS.; RES = COL1; DO i = 2 TO DIM(COLS); IF MISSING(COLS(i)) eq 0 THEN RES = CATS(RES,'/',COLS(i)); END; RUN;

Categories : Sas

With proc means, how to computed a weighted mean with BY statements?
In your example, the weight isn't doing anything to the means, because inside of a by group the weights are all equal - you have no case where frequency has variable amounts. SUM would actually be different (since SUM is sum of the weighted means), but you don't ask for that statistic. Weights only do something if inside of a by group they are not always identical when discussing relative statis

Categories : Sas

Create Program Code out of excel table in SAS
Assuming you have a dataset (called metadata) containing all of you variable names (vname), formats (vfmt), lengths (vlen) and labels (vlbl) from Excel : /* Create VNAME1-VNAMEx, VFMT1-VFMTx etc */ data _null_ ; set metadata end=eof ; call symputx(cats('VNAME',_n_),vname) ; call symputx(cats('VFMT',_n_),vfmt) ; call symputx(cats('VLEN',_n_),vlen) ; call symputx(cats('VLBL',_n_),vlbl) ;

Categories : Sas

Indicator for Top3 and ranking across ros
Your method would work, but there's a much simpler way of doing it. You could use an array, which reads across rows, however I'm using an even easier way of reading across rows. The OF statement can be used in conjunction with a summary function to calculate values across rather than down. The LARGEST function returns the largest nth value from a range, so you can compare field A to the 3rd

Categories : Sas

how to do this summation in SAS
How about this? DATA WANT; SET HAVE; BY ID; IF FIRST.ID AND LAST.ID THEN TOTALQTY = QTY; ELSE IF FIRST.ID THEN TOTALQTY = QTY; ELSE TOTALQTY+QTY; RUN;

Categories : Sas

Subsetting a dataset by selecting variables based on keywords in their name in SAS
You probably want to query sashelp.vtable which holds the metadata about your data set. Assuming your data is in the library WORK and called TABLE the following creates a list of the variables that end in ASK. proc sql; select name into :varlist separated by " " from sashelp.vcolumn where libname="WORK" and memname="TABLE" and upcase(name) like '%_ASK'; quit; *To rename the variables with MI

Categories : Sas

Counting combination of multiple variable frequency in SAS
This produces the desired output. What is happening here is that you need to use the last variable in the BY statement for everything with first./last. processing. If you need to know why, put a few put _all_; in the datastep to see what is what value at different points. You shouldn't check for first.Date at any point, because if first.Date is true then first.ID is always true (by definition,

Categories : Sas

Delete old data from work tables and utilloc
I am using FORFILES. This example will delete the files older than 30 days, run it as a .bat file. It takes three arguments, path, days and extension: call :DeleteLogs D:SASLev1Logs 30 * exit /b 0 :DeleteLogs cd /d %1 FORFILES /D -%2 /M *.%3 /C "cmd /c del /Q @path" GOTO :EOF

Categories : Sas

Plotting line plot in SAS with discontinuous data
This is a difficulty for SAS, but one that can be managed. I have two solutions: Solution 1) Keep the hour as a column in the data, but also add a date/time field to denote that the time is always increasing. Use the date/time field and Decline Rate within gplot, but format the date/time field to only show hours. Solution 2) Add a new column to denote the order data temp; set temp; order =

Categories : Sas

SAS User defined informat to read in phone numbers
The only way to create an informat of this type would be to specify an individual character string and informatted value for every possible phone number you want to match, which obviously isn't a practical approach. However, you can easily create a new variable that contains only the digits from the raw imported text, e.g. data _null_; phone_raw = '(123)456-7890'; length phone_digits $10

Categories : Sas

creating a list of input and output data files generated during a session run - SAS
You probably have two options: parsing a log file or making a snapshot of dictionary.tables before and after every macro call and extracting the differences. I would prefer an ( easier :)) second option, e.g. like PROC SQL; CREATE TABLE BEFORE AS SELECT CATS(libname,".",memname) AS fname FROM DICTIONARY.tables WHERE libname in ('WORK'); QUIT; PROC SQL; CREATE TABLE AFTER AS SELECT CATS(libname,"

Categories : Sas

sas vlookup in the same line from another dataset
I see what you're trying to do, you're CALLING the dataset by the NAME "VlookUp". I see why that's confusing to some on here (myself included) who use that lookup function in Excel. Okay, to SAS: This task is difficult to frame in the context of a normal SAS readin because SAS input statements (or PROC IMPORT, for that matter) expect fields to be in the same order on each line, even if length var

Categories : Sas

How to resolve apperant symbolic reference when import into SAS
Use single quotes (') instead of double ("). SAS will then interpret the quoted path as a literal string without trying to resolve apparent macro variables (which always start with &) that it contains. I prefer to use single quotes in general, and only employ double quotes when I explicitly want to include a macro variable.

Categories : Sas

Compute growth rate, improvements over PROC EXPAND
You can use a data step entirely. This assumes you're asking for the four previous rows. I'm not sure what [1,2,3,4] means, though, so you'll have to fill in exactly what that means in the growth rate. %let numlags=4; data want; set have; array lags[&numlags] _temporary_; *temporary arrays are retained!; growth_rate = cov(of lags[*])/var(of lags[*]); *if you want cov of the 4 lags di

Categories : Sas

SAS Visual Analytics Cross Table Frequency Count
What version of SAS Visual Analytics are you using? For 6.3 you should be able to get to what you want by creating a "Percent of Subtotals" derived measure. This applies to crosstab only. You can choose the subtotal value for the rows or for the columns in the crosstab.

Categories : Sas

Proc GLM with a list of binary dummy variables
Not sure whether this counts as an easier solution :), but you can construct a macro variable IALL DATA I; DO i = 1 TO 40; OUTPUT; END; RUN; PROC SQL NOPRINT; SELECT VAR into: IALL SEPARATED BY " " FROM (SELECT CATS("dayofweek*binvar",PUT(I,2.0)) AS VAR FROM I); QUIT; and use it in PROC GLM proc glm class dayofweek binvar1-binvar40 model outcome = &IALL. /solution run;

Categories : Sas

How to import excel data into sas
The following should work regardless of how many rows precede your data, provided the rows preceding your data are entirely blank. libname xl excel 'C:somefile.xlsx'; data sheet; set xl.'Sheet1$'n; run; libname xl clear; This sets up your Excel workbook like a database and the sheets are referenced directly like tables. I should note that my setup is 64-bit SAS 9.4 with 64-bit Excel; it's

Categories : Sas

SAS : select several observations with same identifier based on a condtion true for just one of them
The easiest way I can think of is to create a table of the identifier and then join back to it. data temp_ID; set TEST; where var = 1; run; proc sql; create table output_data as select b.* from temp_ID a left join TEST b on a.identifier=b.identifier; quit;

Categories : Sas

How to import SAS7BDAT database to Stata without SAS
This blog describes how to export a SAS dataset using PowerShell

Categories : Sas

Change characters at specific position in a string in SAS
Yes, substr() = is what you're looking for. See here for details. substr(string2, 5) = 'zzzz'; The substr(variable,position<,length>) = function can also take an third argument to define the length of the segment to be replaced.

Categories : Sas

How to delete the row with missing character values using SAS
I would be inclined to use proc sql. Something like: proc sql; create table newchar as select * from character where id is not null and type is not null and time is not null; quit;

Categories : Sas

Adjusting column width within sas
Since you haven't assigned the longest value the first time the variable 'Status' is assigned, it was truncated in your DATA step. You need to add to your DATA step length Status $ 11; Further information is provided here http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001336069.htm

Categories : Sas

Literal contains unmatched quote. (SAS)
Here's an alternative approach to adding the quotes. It's pretty basic - it doesn't check whether the input is already quoted, and there must be exactly 1 space between list items, and there must be no leading or trailing spaces in the input list, but you can adapt it to suit your needs: %let list = a b c; %macro qlist(LIST); %sysfunc(compbl( %do i = 1 %to %eval(%sysfunc(count(&LIST, %str( ))

Categories : Sas

Replacing Spaces in a macro variable value with the quotes with space
Without debugging either of your approaches above, I can offer a third: %let str8 = %sysfunc(prxchange(%bquote(s//"/),-1,%quote(&str7.))); *"; The prxchange() function tells SAS to replace every word boundary () with a ". As far as when to use bquote(), vs quote(), it's all documented online, but honestly I usually resort to trial and error. The *"; does nothing, but it makes things loo

Categories : Sas

SAS : keep if exists
How about just adding it to the table if it doesn't already exist? /*look at dictionary.columns to see if the column already exists*/ proc sql; select name into :flag separated by ' ' from dictionary.columns where libname = 'WORK' and memname = 'AREA_I' and name = 'VAR1'; run; /*if it doesn't, then created it as empty*/ %if &flag. ne VAR1 %then %do; data area_i; set area_i;

Categories : Sas

When using PROC FREQ (etc.) in SAS, it includes the missing values that I created in PROC FORMAT. How do I exclude these missing values?
This is an example of SAS doing something a bit different than you'd expect. SAS will collapse missing-formatted values into missing, if there are any true missings. This is not because you formatted them as . though - it will collapse anything into missing that you format to the same result as missing, even if that's not a missing value. If there aren't any values with an underlying (unformatt

Categories : Sas

Using PROC SORT and DATA _NULL_ to produce report with SAS
Here's how I'd do it, trying to stick to mostly how you're doing things. You've got a lot of extra stuff in there you don't really need. I don't know why you're using COUNT (a character function) for example towards the end. Also not sure why you're using %eval() in the macro variable - that's not doing anything. No idea what takes array is doing - is that something else? Overall though your

Categories : Sas

Intermediate variables in a SAS macro
That macro would have to be executed inside of a data step. Those are data step variables and statements and can't be executed in open code. You also can't use %put for that purpose - you need to use put.

Categories : Sas

Add title to a SAS dataset
If I understood correctly, what you want to accomplish is called Label of SAS dataset. You can add label to your dataset when creating it by using dataset option LABEL. You should be able to use it anywhere you can use dataset options and you're creating dataset, e.g.: data title (label="Mean income (note: incomes < $1000 have been excluded)"); length var1 8; run; proc sql; create table title

Categories : Sas




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.