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

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

call java class from SAS. ERROR: Can not find class

data Numbers; do i=1 to 10; output; end; run; data PrimeNumbers; set Numbers; if _N_=1 then declare javaobj j("C:\Program Files\Java\jdk1.7.0_10\bin\checkPrimeNumber"); isPrimeNumber=j.callIntMethod("checkPrimeNumber",i); if isPrimeNum

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

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

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

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