sas-macro

Obtaining minimum maximum output of a macro (function)

时光总嘲笑我的痴心妄想 提交于 2019-12-12 03:39:08
问题 I want to find to find extreme values produced by a macro as a function of input parameters: For example purposes here is some data: data Input_data; input X Y; cards; 10 15 20 18 30 27 33 41 ; run; The following is not the actual formula (as the minimum for this is easily found analytically.) and I want computational method. For examples sake I have semi-empirical rule, which takes three parameters in: %macro Function(const1, const2 const3); data output; set input; X_eff1=((X > &const1.)*(X

SAS summary statistic from a dataset

断了今生、忘了曾经 提交于 2019-12-11 17:42:14
问题 The dataset looks like this: colx coly colz 0 1 0 0 1 1 0 1 0 Required output: Colname value count colx 0 3 coly 1 3 colz 0 2 colz 1 1 The following code works perfectly... ods output onewayfreqs=outfreq; proc freq data=final; tables colx coly colz / nocum nofreq; run; data freq; retain colname column_value; set outfreq; colname = scan(tables, 2, ' '); column_Value = trim(left(vvaluex(colname))); keep colname column_value frequency percent; run; ... but I believe that's not efficient. Say I

Dynamic macro variable access SAS

偶尔善良 提交于 2019-12-11 16:05:27
问题 I've used call symputx to create a list of macro variables Item 1 to Item N and now I want to transfer them to an array in another datastep so that spot 1 in the array gets Item1, spot 2 gets Item2, etc. do j=1 to &num_OR; rulesUsed{j}=&&Item&j; end; I read that the double ampersand syntax is the way to reference macro variables like this but I keep getting all sorts of errors. I'm sure there's a simple way around this but I'm new to SAS and no document I've read through that's come up in

compare cell entries and return values In SAS

放肆的年华 提交于 2019-12-11 14:20:38
问题 just would like to compare cell entries and return values. coustmer_NO id A1 A2 A3 A4 1 5 10 20 45 0 1 13 0 45 2 5 2 4 0 10 7 8 2 3 7 9 55 0 2 10 0 0 0 0 3 4 90 8 14 3 3 10 20 7 4 15 how to count the ID that has (value > 030) for each customer_no then, the min number of values before 030 appears. The expected output would be something like: cosutmer_no , count_ac_num , values 1 2 1 2 1 1 3 1 3 回答1: I would recommend converting to a more vertical structure. Then you can begin trying to apply

Macro Do loop not working properly in RSUBMIT

一曲冷凌霜 提交于 2019-12-11 12:39:14
问题 So I have this code that works well for one year, but I need to convert it as a loop so it works for years from 1970 to 2015. Here is the code for 1 year that I specify in a %let statement. %let year=1970 rsubmit; data home.historical_returns_&year; set home.crspdata; where (year <= &year - 1) and (year >= &year - 5); returns_count + 1; by id year; if first.id or missing(tot_ret) then returns_count = 1; run; endrsubmit; So far, that code works great for me. Now, I am trying to use a loop so I

SAS macro function to get file modified date on linux

拈花ヽ惹草 提交于 2019-12-11 04:55:43
问题 Working on a macro function to return the modified date of a file as a SAS date, that will run on Linux (SAS 9.3). I want to avoid using OS commands (e.g. piping the results of an LS command) as code needs to work in an environment with NOXCMD. Below is a first draft (no error handling code, etc), using finfo(). Was disappointed by the format of the date returned by finfo(), e.g."Fri Apr 10 14:54:10 2015". Then was more disappointed by my inability to input() this string without the ugly

Automating table/object name scan and search in SAS

北城以北 提交于 2019-12-11 03:14:08
问题 OK I'll start with the problem: I have product tables being created every week which are named in the format: products_20130701 products_20130708 . . . I'm trying to automate some campaign analysis so that I don't have to manually change the table name in the code every week to use whichever product table is the first one after the maximum end date of my campaign. e.g %put &max_enddate.; /*20130603*/ my product tables in June are: products_20130602 *products_20130609* products_20130616

How to call a macro in a data step that updates a macro variable and use that value immediately?

☆樱花仙子☆ 提交于 2019-12-11 02:32:21
问题 The following example is very simple and might be solvable in an easier way. However, I am interested in making it work. The following example is based on the cars-dataset of the sashelp-library. First, I have a macro called fun: proc contents data = sashelp.cars out = mycontents; run; %macro fun(var); proc sql noprint; select count(distinct(&var.)) into :obs from sashelp.cars; quit; %mend; Now I want to call the macro but only to update obs (from the input statement). I use: data work.test;

SAS Macro in macro

↘锁芯ラ 提交于 2019-12-11 02:23:08
问题 I have one question regaring %macro. Can I set %macro in another %macro? Short example - "picture" of situation: %macro Tier_1(); %do Iter = 1 to &i; %macro Tier_2() proc sql noprint; select 1*&Iter into :var from work._PRODSAVAIL ;quit; %put &var; %mend; %Tier_2(); %end; %mend; %Tier_1(); 回答1: The answer to your question is "yes, it is possible." But it's poor style. The identical results from above will occur if you simply move the macro definition for %Tier_2 outside of macro Tier_1, but

How to use arithmetic operators with SAS macro variables [duplicate]

淺唱寂寞╮ 提交于 2019-12-11 00:58:56
问题 This question already has an answer here : Prompt or Macro Variables used in calculations (1 answer) Closed last year . I have a data set like this; DATA work.faminc; INPUT famid faminc1-faminc12 ; CARDS; 1 3281 3413 3114 2500 2700 3500 3114 3319 3514 1282 2434 2818 2 4042 3084 3108 3150 3800 3100 1531 2914 3819 4124 4274 4471 3 6015 6123 6113 6100 6100 6200 6186 6132 3123 4231 6039 6215 ; RUN; I can create a variable and do some stuff with it like, %let N=12; DATA faminc1b; SET faminc ;