sas-macro

SAS if statement in do loop

泄露秘密 提交于 2021-02-18 19:30:55
问题 Hi I am trying to write a macro function with do loop and if statement. I think I have messed up the if-then do and do loop and I can't figure out the problem. I have a table of kids information, which contains columns like age, gender, sports, instruments etc,. My original code, which works, looks like this: data old; set new; if sports in ("football","basketball") and age <=7 then type =1; else if sports='swimming' then type=2; if special_kid=. then do; if piano ^=. and piano_1 ^=. then do;

Macro returning a value

醉酒当歌 提交于 2021-02-18 05:13:21
问题 I created the following macro. Proc power returns table pw_cout containing column Power . The data _null_ step assigns the value in column Power of pw_out to macro variable tpw . I want the macro to return the value of tpw , so that in the main program, I can call it in DATA step like: data test; set tmp; pw_tmp=ttest_power(meanA=a, stdA=s1, nA=n1, meanB=a2, stdB=s2, nB=n2); run; Here is the code of the macro: %macro ttest_power(meanA=, stdA=, nA=, meanB=, stdB=, nB=); proc power;

Macro returning a value

自古美人都是妖i 提交于 2021-02-18 05:10:22
问题 I created the following macro. Proc power returns table pw_cout containing column Power . The data _null_ step assigns the value in column Power of pw_out to macro variable tpw . I want the macro to return the value of tpw , so that in the main program, I can call it in DATA step like: data test; set tmp; pw_tmp=ttest_power(meanA=a, stdA=s1, nA=n1, meanB=a2, stdB=s2, nB=n2); run; Here is the code of the macro: %macro ttest_power(meanA=, stdA=, nA=, meanB=, stdB=, nB=); proc power;

SAS Macro Do LOOP

家住魔仙堡 提交于 2021-02-10 15:19:46
问题 I want to have a sas macro loop by even years, so the do loop would jump from 2006 to 2008 to 2010...all the way to 2018 and not from 2006 to 2007. When I do a %by = 2, SAS doesn't work and gives me an error message. What is the best solution? I have the following Code: %macro import; %do I = 2006 %to 2018; data BTI&I; set edited.Bti_&I; year=&I; run; %end; %mend import; %import; 回答1: Add the %by 2 keyword to increment intervals of 2. I would also recommend passing the start and end years as

Transforming expansive “Check all that apply” type questions into random selection of lesser items

孤者浪人 提交于 2021-01-29 15:57:24
问题 I have been facing some difficulties in managing dietary data regarding cereal consumption. The question allows participants to select as many cereal types that they eat (among 300+ choices). I would like to collapse this into just two answers through random selection. The data structure is posing problems. I will outline my problem below… 1.) Structure of the data now: Respondents are allowed to select all cereals that they “usually” eat. The data looks like (1 is replaced with a code for

adding a meta user to a meta group in sas

泄露秘密 提交于 2020-08-26 04:53:19
问题 I've around 600 meta users in SAS EGRC 6.1 in the platform in SAS 9.4. I want to add those users to a meta-group. for this, I'm using code below libname current '/tmp/temp1'; /* for the current metadata */ libname addgrps '/tmp/temp2'; /* current augmented with the changes */ libname updates '/tmp/temp3'; /* for the updates created by the mducmp macro */ options metaserver=abc metaport=8561 metauser='sasadm@saspw' metapass='xyz123' metaprotocol=bridge metarepository=foundation; %mduextr

SAS: Run SQL-query using a macro

会有一股神秘感。 提交于 2020-04-30 06:31:28
问题 Using an answer from this thread, I was trying to get to work the following code. I have a list of sql-queries in a table plus an id for each query. Now I'd like to have the results of these queries plus the id as another table. /* The Macro */ %macro run_query(q,id); proc sql noprint; select count into: count from (&q.) a; quit; %mend; /* Some fake-data */ DATA queries; INPUT id :$12. query :$3000.; INFORMAT id $12.; INFILE DATALINES DSD; DATALINES; 01,SELECT COUNT(*) AS count FROM sashelp