## SAS: Most common links (like a MODE) solved by recency?

I have data like this: data mydata; input ID $Val$ Date; datalines; 1 A 2010-12-01 1 B 2010-12-03 1 A 2010-12-04 1 B 2010-12-08 2 X 2009-10-01 2 X 2009-10-02 2 Z 2009-10-03 ; run; I would like the mode returned where it exists. ID 1, however, doesn

## I can not create a variable using the macro in the Data step using SAS

data freq;; input placebo ; cards; 3 ; Run; data freqt; set freq; %macro freq1 (arm=,pct=,result=); %if &arm ne . %then &pct=&arm*100; %if &pct ne . %then %do; %if &pct le 10 %then &result = "test"; %end; %mend freq1; %fr

## SAS macro error with call running

I have the following code that is being used generate running totals of features for the past 1 day, 7 days, 1 month, 3 months, and 6 months. LIBNAME A "C:\Users\James\Desktop\data\Base Data"; LIBNAME DATA "C:\Users\James\Desktop\data\Data1

## SAS random table with non-recurring items

Could you please help me. I would like to generate a random array from 0 to 5 and I'm using this function rand_num = int(ranuni(0)*5+1) But I would like to generate a random array with a nonrecurrent elements. For example (1,2,3,4,5) (3,1,5,4,2) etc.

## SAS Chi Square test

I have the following dataset on which I intend to perform a chi square test (all variables being categorical). Indicator Area Range1 Range2 0 A 17-25 25-50 0 A 17-25 25-50 0 A 17-25 25-50 0 A 17-25 25-50 0 A 0-17 25-50 1 B 17-25 25-50 1 B 0-17 17-25

## The variable char in the clause is not accessible

i want to access char variable in where clause like below--> %macro obs(indsn=, outdsn=, clause=, col=, optr=, subset_val=); data &outdsn; set &indsn; &clause &col &optr &subset_val; run; proc print data= &outdsn;run; %mend

## Create a SAS macro to create a macro variable

I have created a SAS macro, macro A, that takes in a variable name and returns transformed versions of that name i.e. if you run %A(asdf) you get out asdf_log asdf_exp asdf_10. I want to write another macro, macro B, that takes the output from the fi

## SAS MAcro flow explanation

Following this schema I can understand that macro are resolved before the PDV is even created. But i realy can't figure out how from this code. data ds; input id name \$ value ; datalines; 1 pluto 111 2 paperino 222 3 trump 333 4 topo 444 5 pippo 555

## Multiple comparison OR

I have a group of variables , say b1-b30 and i need to test same condition on same variables among themselves like, if b1='a' or b2='a' or b3='a'.. and so on. is there any solution in SAS macros or using of sas arrays to do this task to avoid writing

## sas macro loop to rename the variable

Hi I am trying to rename variables using SAS Macro loop. %Let t1=12Mth; %Let t2=20; %Let t3=30; %Let t4=40; %Let t5=50; %Let t6=60; %macro Re(time); %Do I = 1 %to &time.; data MilkNew; set Milk; rename MT&&t&I..Sp=MTSp&&t&I.; r

## SAS Macro Variable with commas to convert between single quotes with commas

Could someone help me how I can get a macro variable updated with single quotes. I am getting numbers as comma separated values from a Dataset like below: 2108008080, 2108008081, 2108888082, 2108858090, 213856345 etc I have to pass each of these reco

## When to use double quotation marks when referring to a SAS macro variable

While referencing a SAS macro variable, when do I need to enclose it in double quotes and when should I not? i.e When to use "&var_name" and when to use &var_nameQuote marks are not part of the macro language. The job of the macro langua

## SAS Enterprise Guide and Conditional Macro Values

I have a simple macro that checks for the existance of a Dataset (DATA01): %GLOBAL base_exists; %MACRO does_base_exist(); %IF %SYSFUNC(exist(DATA_01)) %THEN %LET base_exists= 1; %ELSE %LET base_exists= 0; %MEND; %does_base_exist(); %PUT Base exist ch

## Implementing recursive bisection in SAS

First question here. Basically, I want to implement a recursive bisection algorithm in SAS via the use of macros. I have already written a macro that takes two arguments (the lower and upper endpoints of the current interval) and produces a table con

## Macro SAS function conditional on the value of the macro variable

I have a SAS project (EGv7.1) that allows the user to specify a value on the first line. Then, other processes are invoked based on the value specified. One of these is that some other macro variables are assigned. Below is what I have, and it does n

## Why does my macro behave differently with call execute ()?

Using SAS, I often want to perform an action on each row of a dataset. To do so, I use a command I found on a tutorial : call execute(). As I'm not very familiar with SAS environment, I tend to use macro-functions to do anything I don't know how to a

## Replace spaces in a macro variable value with quotation marks with space

I want to replace space between variables passed in a macro variable with double quotes with space, i.e. " ". Please find below the code I am using for the same and the result I am getting. %let str7=ABC DEF UVW XYZ; %let str8 = %qsysfunc(quote(

## SAS Do loops: uses a loop variable inside the loop to create lagged variables

I would like to create variables containing lagged values of a given variable for a large number of lags. How could I do this? I try the following: data out; set in; do i = 1 to 50; %let j = i; lag_&j = Lag&j.(x); end; run; How can I get the loop

## Make a SAS data column in a macro variable?

How can I convert the output of a SAS data column into a macro variable? For example: Var1 | Var2 ----------- A | 1 B | 2 C | 3 D | 4 E | 5 What if I want a macro variable containing all of the values in Var1 to use in a PROC REG or other procedure?

## sas_ variable value inside a like in a macro

I need to use the following code inse a macro: proc sql; select name into :lista separated by ' ' from dictionary.columns where libname='LABO2' and name like 't1_%' and name like "%5"; quit; But when I write: %macro prue(numero); proc sql; selec

## How to use the sas macro to sample multiple data sets

I have several datasets with the same structure(two variables:"code" and "group") while different in dataset name(with no rule). Now I have to do simple random sampling in these datasets, the method is selcet one observation from each

## Analyzing the JSON object in a SAS macro

Here is the input JSON file. It have to parse in SAS dataset. "results": [ { "acct_nbr": 1234, "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAd

## Optimize the construction of a SAS table with macros

I have a SAS program that dynamically builds a table with a macro like so: %macro Projection; %do i=1 %to &number_of_Years; %Advance_Years; proc sql; create table Projection as select *, Year_&previous_year.*(1+return) as Year_&current_year. f

## Generate a file name from the variable from inside the loop in SAS PROC IML

I am trying to breakdown data file into small files, with one of the variables as a part of the name for those files. To be specific, I have a bunch of Census tracts, plus other variables. I am reading them into the matrix, perform some operations an

## How can I call a variable whose name is found as a string under another variable in SAS?

I have one variable that lists the variable name where the information I need is stored. This variable stores all the variable names as strings. I am trying to create another variable that just includes whatever is in the row of the variable whose na

## How can I make a macro for each observation in the sas dataset?

Here is the macro code..... libname myfmt "&FBRMrootPath./Formats"; %macro CreateFormat(DSN,Label,Start,fmtname,type); options mprint mlogic symbolgen; %If &type='n' %then %do; proc sort data=&DSN out=Out; by &Label; Run; Data ct

## SAS compares two text files (Unix / Windows)

I need to compare two text files (in different directories) to see if they are different (a binary result is fine). Given a dataset such as the one below, is this possible within a datastep? Pathname c:\one\text1.txt c:\two\text1.txt c:\one\text2.txt

## Concatenation of SAS variables via the data step

I am looking for a way to create a string variable containing certain values of the dataset while going through the data step. Example data set work.test: AddToStringYN Value Y One Y Two N Three Y Four N Five So in the end, the variable would look li