How to define a macro variable using equation with variables from dataset in SAS Miner - macros

I am trying to use &let in the beginning of my script to define a new macro variable... it should consist of equation from variables from dataset. The equation looks something like this, but SAS always gives me error like this (Runtime error was encountered, please see the log...).
The equation:
%let var_bad = (receivable_actual * 0.5) -
(EM_EVENTPROBABILITY * 0.02 * receivable_actual) +
((1 - EM_EVENTPROBABILITY) * 0.5 * (receivable_actual - amt_instalment));
Can you guys help me fix it?
Thanks,
Adam

#Jetzler: These are the errors it shows me in log.
ERROR 214-322: Variable name ( is not valid.
ERROR 22-7: Invalid option name -.
ERROR 23-7: Invalid value for the KEEP option.
---
23
1 ! (receivable_actual * 0.5) - (EM_EVENTPROBABILITY * 0.02 * receivable_actual) + ((1 - EM_EVENTPROBABILITY) * 0.5 * (receivable_actual - amt_instalment))
- -
214 22
ERROR 214-322: Variable name * is not valid.
ERROR 22-7: Invalid option name +.
1 ! (receivable_actual * 0.5) - (EM_EVENTPROBABILITY * 0.02 * receivable_actual) + ((1 - EM_EVENTPROBABILITY) * 0.5 * (receivable_actual - amt_instalment))
--- -
214 22
14338 + rename=(em_eventprobability = score_no_call));
-------
22 22
201 76
ERROR 214-322: Variable name 0.5 is not valid.
ERROR 22-7: Invalid option name *.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, END, INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, DATA, LAST, NULL.
ERROR 201-322: The option is not recognized and will be ignored.
ERROR 76-322: Syntax error, statement will be ignored.

Why don't you just calculate the variable in the dataset and then select it into a macro variable?

Related

How to calculate and SHOW value of #define macro VStudio

I know how to show expanded macro in C.
However, I am interested in how to show a calculated value of a macro.
Precompiler definitely calculates macro values in order to do #if(a>b) statement:
#define STRINGIFY(s) XSTRINGIFY(s)
#define XSTRINGIFY(s) #s
#define ONE_BYTE_Tx_Time 11
#define NUM_OF_BYTES 16
#define BUSY_TIME 132
#define TOTAL_TIME 300
#define AVAIL_TIME (TOTAL_TIME-BUSY_TIME)
#define RESP_TIME (ONE_BYTE_Tx_Time * NUM_OF_BYTES)
#pragma message ("AVAIL_TIME =" STRINGIFY(AVAIL_TIME))
#pragma message ("RESP_TIME =" STRINGIFY(RESP_TIME))
#if (AVAIL_TIME <= RESP_TIME)
#error "not enough time"
#endif
The output during compilation is:
AVAIL_TIME =(300-132)
RESP_TIME =(11 * 16)
fatal error C1189: #error : "not enough time"
So, precompiler had calculated two integers, compared them and outputted an error.
My question is:
how to show actual RESULT of macro calculation during compilation?, i.e.
AVAIL_TIME = 168 // which is (300-132)
RESP_TIME = 176 // which is (11 * 16)
The formulas expansion can be rather complicated, so it is useful to see result during compilation, without running of the code:
AVAIL_TIME_in_SysTicks =(((75000000/1000000) * (1000000/2500)) - 2 * ((((75000000/1000000) * ((1000000000/900000) + 1)*(10 + 0x00000000/0x00000008) + 2)/1000) * 16))
Thanks, Igor

ultisnips: How to "freeze" vim.current.window.cursor value for snippet

I had a snippet that used to work well (neovim 0.2.0)
snippet #= "comment ===" b
# `!p snip.rv = '=' * (78 - vim.current.window.cursor[1])`
# ${1:comments}
# `!p snip.rv = '=' * (78 - vim.current.window.cursor[1])`
endsnippet
This snippet is basically writing python comments block when triggered,
where the length of "=" depends on the position of the cursor.
For a few days now (I don't know which update makes it failing), the length of "=" is decreasing as long as I type my comment.
It looks like vim.current.window.cursor[1] is constantly re-evaluated.
Any idea how to "freeze" the value?
I finally found:
snippet #= "comment ===" b
`!p
if not snip.c:
width = int(vim.eval("78 - virtcol('.')"))
snip.rv = '# ' + '=' * width`
# ${1:comments}
`!p snip.rv = '# ' + '=' * width`
endsnippet

Setting to get the pretty rational phrases in command window

Here I've a rational relation :
A = -(2*omega*(5*omega^4 - 9907*omega^2 + 550))/(omega^6 + 5025*omega^4 + 3344500*omega^2 + 11902500)
Is there any setting in Matlab that shows computed results in command window 'like (A)' pretty as below form (both for numeric and parametric results):
-(2*omega*(5*omega^4 - 9907*omega^2 + 550))
A = --------------------------------------------------------
(omega^6 + 5025*omega^4 + 3344500*omega^2 + 11902500)
You might want to check out pretty.
From the documentation:
pretty(X) prints symbolic output of X in a format that resembles typeset mathematics.
As an example:
/ 2 \
sqrt(3) | ---- + #2 | 1i
\ 9 #2 /
------------------------
2
I don't have the symbolic toolbox, so I can't illustrate with your example.

read .yml files in matlab

I would like to read .yml files in Matlab. These files contain coordinates x and y of key points on a face image. I looked for different tools but I don't seem to find any answers.
My .yml files look like this
YAML:1.0
Image file: "00032009.jpg"
Contours count: 8
Contours:
-
Name: FO
Count: 41
Closed: 0
Points:
-
x: 682.5947265625000000
y: 743.1998901367187500
-
x: 685.9638061523437500
y: 771.3800659179687500
......
and so on
Note 00032009.jpg is an image of a face
x and y are coordinates of a point on a face Eg: the right corner of an eye etc
Could you please point out a way to read the file and then display the points on the face image?
Edit 1: Here is the error I get
Error: File: ReadYamlRaw.m Line: 14 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
What is weird is line 14 in ReadYamlRaw.m
[pth,~,~]= fileparts(mfilename('fullpath'));
Parse error at ','(second one) and ']' usage appears to be invalid matlab syntax.
So what is the use of ~ in there and why is there an error?
Edit2: I replaced the ~ in the line above with dummy variables then I get this errors O_O
Error using ==> ReadYamlRaw>scan at 81
Unknown data type: logical
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>scan_list at 116
result{ii} = scan(i);
Error in ==> ReadYamlRaw>scan at 77
result = scan_list(r);
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
I also tried with a different yml file that looks like this
%YAML:1.0
RE-C:
x: 919
y: 580
LE-C:
x: 1209
y: 597
N-C:
x: 1063
y: 698
FO-B:
x: 1045
y: 1114
REL-O:
x: 852
y: 597
REL-I:
x: 986
y: 600
REL-T:
x: 918
y: 564
And I get the following errors
Java exception occurred:
while scanning a directive
in "<string>", line 1, column 1:
%YAML:1.0
^
expected alphabetic or numeric character, but found :(58)
in "<string>", line 1, column 6:
%YAML:1.0
^
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirectiveName(ScannerImpl.java:1028)
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirective(ScannerImpl.java:990)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDirective(ScannerImpl.java:534)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:251)
at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
at
org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:198)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
Maybe someone can make something out of these or you could point out another set of functions that would work? I searched but didn't find any except this one.
It's YAML file indeed (as #DavidBrown mentioned in his comment, the extension does not matter). But it has some problems. Don't know if it's due to wrong YAML format or MATLAB implementation.
I've installed YAMLMATLAB and played a little with your file.
YamlStruct = ReadYaml(yaml_file);
YAMLMATLAB returns error if the files is feed as is. It works only if I comment the first line and remove spaces from field names. So the beginning of the file looks like this:
#YAML:1.0
Imagefile: 00032009.jpg
Contourscount: 8
...skipped the rest...
Then I get the correct structure. For example you can access the 1st point's x coordinate as
YamlStruct.Contours{1}.Points{1}.x
ans =
682.5947
UPDATE
Space in filed names is actually a known problem in YAMLMATLAB. See the report and possible solution here.
UPDATE 2
According to comment from #Jirka_cigler (YAMLMATLAB developers group):
In the program release 0.4.3 we added support for whitespaces in field
names, so the problem should not appear again.
Great!
I've also removed previous developers comment on the problem in the first UPDATE since it's not true any more.
ZozaniDB Database Toolbox comes with a Matlab-native YAML implementation that handles the .yml file here. To parse a string or a file, use:
>> yaml_parse ( str )
>> yaml_read ( filename )

How do I capture the output from the "present" function and store it in a string

In Matlab, I have a IDPOLY object which I wish to "present" and store the resulting text in a text file.
eg if a is an IDPOLY object and I do
>> present(a)
I get
Discrete-time IDPOLY model: A(q)y(t) = B(q)u(t) + e(t)
A(q) = 1 - 1.31 q^-1 + 0.2425 q^-2 - 0.431 q^-3 + 0.4987 q^-4
B1(q) = 0.01357 + 0.04006 q^-1 - 0.04489 q^-2 + 0.007757 q^-3
- 0.1761 q^-4 + 0.06396 q^-5 - 0.2874 q^-6 + 0.3835 q^-7
B2(q) = -0.006397
Estimated using ARX with focus on data set iddata_est_shift
Loss function 0.0617185 and FPE 0.061879
Sampling interval: 0.025
Created: 24-Nov-2010 13:05:10
Last modified: 24-Nov-2010 13:06:56
Does anyone know how to capture this text as I'd like to write it to a text file in a log file. There are no returned arguments from present.
You can try using the diary command.
I've found the evalc() command which does exactly what I need.
evalc
Evaluate MATLAB expression with capture
Syntax
T = evalc(S)
[T, X, Y, Z, ...] = evalc(S)
and pass the expression as a string.