Recent Activity
Hello World,
The following page explains what Threaded Applications are: "SAS threaded applications are SAS procedures that thread input, output, and numeric operations". Is there a list somewhere that shows what these proc steps are? I tested proc means and proc summary, but the option DBSLICEPARM=(THREADED_APPS, 2) has no effect.
Options That Affect Threaded Reads
... View more

0
2
I am trying to use SAS/IML to perform computations with what in some cases are very small numbers, e.g., less than constant('maceps') and am stymied by my inability to make the expression ndx = loc( vector= max( vector )) return only one value instead of > 1 . When, for example, vector = {8.372E-26 4.63E-103}, the variable ndx will contain {0 0} because the two values in vector are smaller than constant('maceps'), which is 2.2e-16.
I am enclosing the code of an IML module which demonstrates what I want to do, and have included a listing of the inputs and outputs to and from the module for your perusal. For small values of m and p, e.g., .01, computing ( x ## p - y ## p ) ## ( 1/p ) produces values close to 1, and I see that the results include 0 in the output, or some very small number such that computing 1 + number > 1 results in False, e.g., 0, and not True, e.g., 1 .
I will be appreciative for any suggestions because I have tried strategies such as scaling the x and y values by constant('maceps'') or constant('small') but to no avail. Perturbing x[ j ] and y[ i, j ] by adding a uniform random variate in [0,1] # constant('maceps') similarly fails when 1/p is large, e.g., 1/p >> 1. For example,
proc iml ;
a =8.372E-26 ;
b= 4.63E-103 ;
p = .01 ;
c = ( a ## p + b ## p ) ## (1/p) ;
print c ;
quit ;
----------
Output:
---------
c
4.985E-19
TIA,
Ross
options nonotes ;
proc iml ;
reset storage=featclus.featclus ;
load module=_all_ ;
start compute_similarity( x, y, m, p ) ;
/* compute unweighted Lukasiewicz ("normal" (unweighted) Lukasiewicz structure) similarity
*
* purpose: compute similarity between feature vector j, class mean(s) i
*
* parameters:
* x ::= 1 x n_feature vector of features, each column normalized into [0, 1]
*
* y ::= n_class x n_feature matrix of class means, produced from normalized x features
*/
if nrow( x ) ^= 1 then run error( 'compute_similarity', 'Feature vector x must be row vector' ) ;
n_classes = nrow( y ) ; /* # of class means in class mean matrix */
n_feat = ncol( x ) ; /* # of features in x vector */
dist = j( n_classes, n_feat, . ) ;
similarity = j( 1, n_classes, . ) ;
do i = 1 to n_classes ;
do j = 1 to n_feat ;
/* compute similarity btwn x, y for each feature element x[ j ], class mean value y[ i, j ] */
dist[ i, j ] = ( 1 - abs( x[ j ] ## p - y[ i, j ] ## p )) ## ( 1 / p ) ;
end ; /* j */
end ; /* i */
/* compute similarity btwn x, y for each class mean
* dist[ i , : ]` is mean of row vector for class mean i
*/
similarity = dist[ , : ]` ## ( 1 / m ) ;
return similarity ;
finish compute_similarity ;
x = { .1 .2, .3 .4, .5 .6, .7 .8 } ;
if any( x = 0 ) then x[ loc( x=0 ) ] = constant( 'maceps' ) ;
y = { .15 .35, .351 .45 } ;
print x y ;
rslt = compute_similarity( x[1,], y, 1,1 ) ;
print rslt ;
rslt = compute_similarity( x[2,], y, .5, .5 ) ;
print rslt ;
rslt = compute_similarity( x[3,], y, .001, .01 ) ;
print rslt ;
rslt = compute_similarity( x[4,], y, .05, .05 ) ;
print rslt ;
rslt = compute_similarity( x[1,], y, 0.000024943605419, 4.148552428951820) ;
print rslt ;
***store module=compute_similarity ;
quit ; ---------- Output: ----------
x
y
0.1
0.2
0.15
0.35
0.3
0.4
0.351
0.45
0.5
0.6
0.7
0.8
rslt
0.9
0.7495
rslt
0.6600432
0.8439022
rslt
0
6.03E-139
rslt
2.496E-10
3.9649E-6
rslt
8.372E-26
4.63E-103
... View more

0
4
Consider the requirement to convert numeric variables to same named character variables, and the character values must be the formatted numeric values, and the original column order must be maintained. More generally, conversion is rendering process.
My first cut is
%macro num_to_char(data=) ;
%local vars renames reassigns drops formats;
proc contents noprint data=&data out=n2c_contents ; run ;
proc sql noprint ;
select trim(name)||'$'||cats(ifn(type=1,32,length))
into :vars separated by ' ' from n2c_contents order by varnum ;
select cats(name,'=_',varnum), cats(name,'=left(vvalue(_',varnum,'))'), cats('_',varnum)
, cats('_',varnum)||' '||ifc(format='','best32.',cats(format,formatl,'.',formatd))
into :renames separated by ' ', :reassigns separated by ';', :drops separated by ' '
, :formats separated by ' '
from n2c_contents where type = 1 ;
drop table n2c_contents ;
quit ;
%if %length(&renames) %then %do ;
data &data ;
length &vars ;
set &data (rename=(&renames)) ;
format &formats ;
&reassigns ;
drop &drops ;
run ;
%end ;
%mend num_to_char;
If this macro is for a general library, how much harder should it go?
The current implementation has all converted values being stored in a character variable of length $32 (call this the target/container/destination).
Which, if any, of these would be worth pursuing?
Make the target length match the numeric format length
Use format default length in dictionary.formats if not in data set metadata
Shortening the target length to only necessary length (max rendered length)
For example: binary numeric variables 0/1 do not need $32 when converted
With shortened target lengths want to avoid asteriks and truncated results
... View more

0
7
Hi,
Can we calculate minimum detectable effect size for a cluster randomise trial(cRCT)? I have the following situation.
A two arm cRCT with 20 clusters in each arm, average cluster size is 30 (SD=20). Power=80%, Alpha=0.05. Proportion of outcome in the control group is 65%. What difference in the outcome between the 2 arms I can estimate from this study?
Bayzid
... View more

0
3
The correct code is as follows. But I used almost an hour to figure it out and still have questions about it. (ps: I made these mistakes while doing the practice questions on page 285 in Macro1: essentials course notes pdf, that was a complex question.)
1) The correct code and results
%macro ctrylist(ctry1)/minoperator;
%let list1=AT AU CA CH;
%put &list1;
%if &ctry1 in &list1 %then %do;
%put &ctry1;
%end;
%else %do;
%put ERROR: &ctry1 is an invalid country code.;
%put ERROR: Valid country codes include &list1.;
%end;
%mend ctrylist;
%ctrylist(AU);
%ctrylist(zz);
2) How I used almost an hour to make mistakes and correct it. At first I wrote something like this (I did not know what's wrong with my mind then and forgot to write the semicolon ; behind the two %put statements in the %else %do statement, also when debugging I kept ignore this obvious mistake and costed me a lot of time to figure out the problem):
%macro ctrylist(ctry1);
%let list1=AT AU CA CH;
%put &list1;
%if &ctry1 in &list1 %then %do;
%put &ctry1;
%end;
%else %do;
%put ERROR: &ctry1 is an invalid country code.
%put ERROR: Valid country codes include &list1.
%end;
%mend ctrylist;
%ctrylist(AU);
%ctrylist(zz);
And I got error message like this:
I am not good at using error message to help debug, also did not pay attention to where did the error occur. The possible mistakes came into my mind were: 1) maybe the %if &ctry1 in &list1 statement has problem, maybe I should try a &list with commas that separate the values, and 2) maybe the first %put in the first %if %then statement is not necessary. Then I tried something like this:
%macro ctrylist2(ctry2);
%let list2='AT','AU','CA','CH';
%if &ctry2 in (&list2) %then %do;
&ctry2;
%end;
%else %do;
%put ERROR: &ctry2 is an invalid country code.
%put ERROR: Valid country codes include &list2.
%end;
%mend ctrylist2;
%ctrylist(AU);
%ctrylist(zz);
And I got the same error message:
Then I did not know what to do. The only thing came into my mind was, maybe an option minoperator should be added (because in that section in the material there was content of minoperator), then I tried something like this:
%macro ctrylist2(ctry2)/minoperator; %let list2='AT','AU','CA','CH'; %if &ctry2 in (&list2) %then %do; %put &ctry2; %end; %else %do; %put ERROR: &ctry2 is an invalid country code. %put ERROR: Valid country codes include &list2. %end; %mend ctrylist2; %ctrylist(AU); %ctrylist(zz);
And I got the exact same error message. I did not know why I kept ignore the obvious mistake that there was no semicolon ; after the two %put statements, I even did not put my eyesight at the two statements, like I kept ignore an obvious, major mistake intentionally. Then I think I cannot figure it out and was going to post the problem into this community. But right before I post the problem my attention and eyesight somehow switched to and see the mistake: I did not write semicolon ; after the two statements. And I corrected it.
3) What I learnt from the experience: a) do not in a hurry and too eager to find out what is wrong, just look into every details of the code, b)look at the error message, especially where does the error message occur, c) when writing complex macros, keep relax and keep attention focused and enjoy, do not rush. d) When writing macro, it is easy for me to forget the semicolon, or sometimes added unnecessary semicolon or put semicolon at wrong place, I made this mistake twice before, the scenario is like(I forget another example which use a %if %then and where statement in a data step, which has the similar usage of the semicolon, could anyone come up with a similar example, many thanks) this, for this incorrect code I should put the semicolon after the &&b&i right before run; statement and after the %end; statement:
data a;
set %do i=1 to &sqlobs;
&&b&i;
%end;
run;
4) I still have questions about the codes:
a) do %if &ctry1 in &list1 and %if &ctry2 in (&list2) work the same way? I mean the syntax of the %if in statement, the first one does not need the brackets and the second one does need the brackets, isn't it?
%let list1=AT AU CA CH;
%put &list1;
%if &ctry1 in &list1 %then %do;
%put &ctry1;
%end;
%let list2='AT','AU','CA','CH';
%if &ctry2 in (&list2) %then %do;
%put &ctry2;
%end;
b) what does the minoperator options do? why do I need it after the macro name? Without it I got a similar error message (only without the error message about %put).
%macro ctrylist2(ctry2);
%let list2='AT','AU','CA','CH';
%if &ctry2 in (&list2) %then %do;
%put &ctry2;
%end;
%else %do;
%put ERROR: &ctry2 is an invalid country code.;
%put ERROR: Valid country codes include &list2.;
%end;
%mend ctrylist2;
%ctrylist(AU);
%ctrylist(zz);
... View more

0
14
Unanswered topics
These topics from the past 30 days have no replies. Can you help?
Subject | Likes | Author | Latest Post |
---|---|---|---|
0 | |||
1 | |||
0 | |||
0 | |||
0 | |||
1 | |||
1 | |||
0 | |||
1 | |||
0 |