sas-macro

SAS Macro Truncating IDs

纵然是瞬间 提交于 2020-03-25 18:41:46
问题 I am using the ASA24 HEI SAS macro for the SAS University Edition. I believe SAS is truncating my IDs (ASA24 Usernames). In my data (.csv) I have Usernames like After the macro code, the GFHSp040x (x is a natural number) IDs get truncated to GFHSp040. Is this related to how the macro imports? Code below: /*The SAS program (HEI-2015 Individual Scores using multiple days of data from ASA24-2016 and ASA24-2018) ByPerson.SAS */ /*This SAS program can be used to calculate Healthy Eating Index (HEI

SAS Macro Truncating IDs

别说谁变了你拦得住时间么 提交于 2020-03-25 18:41:23
问题 I am using the ASA24 HEI SAS macro for the SAS University Edition. I believe SAS is truncating my IDs (ASA24 Usernames). In my data (.csv) I have Usernames like After the macro code, the GFHSp040x (x is a natural number) IDs get truncated to GFHSp040. Is this related to how the macro imports? Code below: /*The SAS program (HEI-2015 Individual Scores using multiple days of data from ASA24-2016 and ASA24-2018) ByPerson.SAS */ /*This SAS program can be used to calculate Healthy Eating Index (HEI

SAS: lookup data inside a function/subroutine / return an array

左心房为你撑大大i 提交于 2020-01-14 03:10:10
问题 Suppose I like to do something like the following (with exemplary variable names for better readability): take a parameter InParameter and match it to the variable MyVar1 in a dataset MyData return all values for the variable MyVar2 for the filtered observations from a subroutine/function that i can use inside proc sql/datastep This is what I got so far (clearly not working): proc fcmp outlib=work.funcs.MyFunction; function MyFunction(InParameter $); array MyArray ... ; /* Here: Create an

SAS: macro generating data driven subset data files

给你一囗甜甜゛ 提交于 2020-01-06 15:15:14
问题 Using SAS macro, I would like to generate subset of files using data driven method. Can someone direct me where to start? For example, I have a data set like following: data student; var v1 $ v2 $ v3; datalines ; f j 20 f j 20 f j 22 f s 18 f s 18 m j 19 m j 19 m s 20; Instead of using 'if' statement for each variable category, I want SAS macro recognize each value in variables and make subsets of data. Do I need to look into loop function or symput (after making proc freq)? thank you, KKK

How to mask “OR” in sub-macro with variable list passed through using SYSPBUFF in macro

痴心易碎 提交于 2020-01-06 08:28:31
问题 I'm using SYSPBUFF to pass through various numbers of parameters into a macro. Specifically, I am passing through a list of states (inner query) and regions (outer query). One of the states being used is Oregon which abbreviates to "OR" and that one state is causing me error. I previously asked an almost identical question and got a response that solved the problem. However, now I am adding the working macro within another macro and it no longer works anymore. What am I missing in the outer

SAS proc sql inside %macro

▼魔方 西西 提交于 2020-01-05 04:05:31
问题 Firstly I have the following table: data dataset; input id $ value; datalines; A 1 A 2 A 3 A 4 B 2 B 3 B 4 B 5 C 2 C 4 C 6 C 8 ; run; I would like to write a macro so that the user can subset the data by giving the id value. I do proc sql inside the macro as follows: %macro sqlgrp(id=,); proc sql; create table output_&id. as select * from dataset where id = '&id.' ; quit; %mend; %sqlgrp(id=A); /*select id=A only*/ I am able to generate the output_A table in the WORK library, however it has

SAS Do loops: use loop variable inside the loop to create lagged variables

梦想与她 提交于 2020-01-04 13:48:12
问题 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 variable i into the macro variable j or how to use it directly to create the appropriately named variable and for the Lag function? 回答1: Chris J answers the question, but here i'll provide my preferred way of doing this. %macro lagvar(var=,num=); %do

SAS Do loops: use loop variable inside the loop to create lagged variables

☆樱花仙子☆ 提交于 2020-01-04 13:48:10
问题 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 variable i into the macro variable j or how to use it directly to create the appropriately named variable and for the Lag function? 回答1: Chris J answers the question, but here i'll provide my preferred way of doing this. %macro lagvar(var=,num=); %do

How to loop a logistic regression n number of times?

随声附和 提交于 2020-01-03 05:23:12
问题 I got a piece of code on SAS that predicts consumer behavior. So far I did 50 samples with 50 logistic regression by hand, but I'd like to automate this process. Steps are as follows: Create a table with all client having value "1" Create a table with all client having value "0" (below code starts here) Start a loop that: Get a sample of 3000 people from client having value "1" Get a sample of 3000 people from client having value "0" Join those two tables Logistic regression which should get

single quoting values using sql to create macro variable

允我心安 提交于 2020-01-01 19:22:33
问题 I am using a macro in SAS to loop over the data tables in a specific library. I put the metadata information in a data null step and make a comparison with a where statement and my macro variable. My SQL step looks like: proc sql; select quote(trim(code)) into :procedures separated by ', ' from procedures; quit; Some values of code contain values like "45.10" and "G0102", so cannot be coerced to numeric. The macro contains the line: %macro filter_codes(indata, outdata); data &outdata; set