I need to create SAS informat that will change all case versions of 'Male' and 'Female' to digits.
I found in the documentation that there is UPCASE options that does the job. "converts all raw data values to uppercase before they are compared to the possible ranges. If you use UPCASE, then make sure the values or ranges you specify are in uppercase"
Unfortunately after adding the UPCASE option none of the input values is read properly.
The SAS version id 9.2.
My code is below.
options fmtsearch=(WORK);
proc format lib=WORK;
invalue gender UPCASE
MALE = 1
FEMALE = 2
;run;
data _null_;
q='MALE';
x=input(q,gender.);
put q=;
put x=;
run;
The log is:
NOTE: Invalid argument to function INPUT at line 186 column 7.
q=MALE
x=.
q=MALE x=. _ERROR_=1 _N_=1
What is the proper usage of this option?
Very simple, just put UPCASE inside brackets...
Related
I have a column that contains either letters or numbers. I want to add a column identifying whether each cell contains a letter or a number. The problem is that there are thousands of records in this particular database.
I tried the following syntax:
= Table.AddColumn(Source, "Column2", each if [Column1] is number then "Number" else "Letters")
My problem is that when I enter this, it returns everything as "Letter" because it looks at the column type instead of the actual value in the cell. This remains the case even when I change the column type from Text to General. Either way, it still produces "Letter" as it automatically assigns text as the data type since the column contains both text and numbers.
Use this expression:
= Table.AddColumn(Source, "Column2", each if List.Contains({"0".."9"}, Text.Start([Column1], 1)) then "Numbers" else "Letters")
Note: It would have been smart to add sample data to your question so I wouldn't have to guess what your data actually looks like!
Add column, custom column with
= try if Value.Is(Number.From([Column1]), type number) then "number" else "not" otherwise "not"
Peter's method works if the choice is AAA/111 but this one tests for A11 and 1BC as well
I have a query that must set a value if the number is between 2 values, but the output is not ok, I think because that column is a string. Any way to do it even it's string?
(In output I have value as , 5 witch is not ok).
All the values that are incorrect are Integer.
SET lkp_age_category_id = 7
WHERE
age BETWEEN '26' and '35.99';
I guess, only working on the SQL side, you could cast the values right into the query, e.g.:
SET lkp_age_category_id = 7
WHERE age BETWEEN '26'::float AND '35.99'::float;
Also check this answer https://stackoverflow.com/a/13809603/917617.
format in TCL in not working correctly,I am trying to format some text and writing them in a file and then sending that file as a mail to user.
I am seeing that format is correct in Linux but when mail comes to user then format is not proper.
code-
puts [format {%-50s%-170s%-50s%-50s} "Test_Id" "Test_Description" "Test_Ran_Count" "Test_Result"]
puts [format {%-50s%-170s%-50s%-50s} $test_id1 "$mail_desc1" $loop_count $test_result]
puts [format {%-50s%-170s%-50s%-50s} $test_id "$mail_desc" $loop_count $test_result]
output-
Test_Id Test_Description Test_Ran_Count Test_Result
test_id_1 To execute - test_id_1 10 PASS
test_id_2 To execute - test_id_2 10 PASS
here if test_id_2 is big then entire format is shifting,as per format behavior if test_id is less then 50 char then it should not shift other column as I am giving %-50s for test_id.
Format fields (which Tcl borrows from C's sprintf() with very few changes) are a bit tricky. When you use %50s (or %-50s — the - just affects alignment) you are setting a minimum field width. To set a maximum field width, you might use %.50s. Or, more likely in your case, you'll set minimum, maximum and alignment: %-50.50s.
Demonstrating with some narrower fields and simple strings of different lengths:
foreach str {abc defgh ijklmnop} {
puts [format ">%-5.5s< |%-5s| /%-.5s/" $str $str $str]
}
Which produces this output:
>abc < |abc | /abc/
>defgh< |defgh| /defgh/
>ijklm< |ijklmnop| /ijklm/
As you can see, left aligned, completely fixed width requires giving %-N.Ns (for some N).
%let vc = 12025;
ideal output (with format comma ) is 12,025;
but %put %sysfunc(put(&vc,comma6.)) seems not working. Error as below.
ERROR: The PUT function referenced in the %SYSFUNC or %QSYSFUNC macro function is not found.
The PUT function is not available with %SYSFUNC, however you can use PUTN for numeric values, or PUTC for character.
Try :
%put %sysfunc(putn(&vc,comma6.));
An alternative to using the putn() function to format values returned by %sysfunc() is to use the little known 2nd parameter of %sysfunc() like so:
%let vc = 12025;
%put %sysfunc(sum(&vc),comma6.);
The second argument applies a format to the result returned by whatever function %sysfunc() is calling. In the above example, I'm just summing a number by itself which effectively just returns the number. If it was a character value, I could use the cats() function.
Worth noting as it will simplify code if you want to do something like:
%put %sysfunc(putn(%sysfunc(date()),date9.));
as it becomes:
%put %sysfunc(date(),date9.);
I tried to get some data from Firebird database. I have a field "UID", whose value is de6c50a94aee524d9d287a43158360f4 String(16).
When I get it with Ruby, I got:
"UID"=>"\xDElP\xA9J\xEERM\x9D(zC\x15\x83`\xF4"
Why didn't I get a string?
conn.query(:hash , 'SELECT FIRST 1 UID FROM cmd').first
The UID you receive is a binary array, which in ruby is represented as a packed string. To unpack it do the following:
"\xDElP\xA9J\xEERM\x9D(zC\x15\x83`\xF4".unpack('n*').map { |x| x.to_s(16) }.join
# => "de6c50a94aee524d9d287a43158360f4"
Your UID is a 128bit value. The hex string representation of UID can be built with unpack:
str = "%08x%04x%04x%04x%04x%08x" % UID.unpack("NnnnnN")
=> "de6c50a94aee524d9d287a43158360f4"
The reason for the specific formatting is this code is really for UUID's
str = "%08x-%04x-%04x-%04x-%04x%08x" % UID.unpack("NnnnnN")
=> "de6c50a9-4aee-524d-9d28-7a43158360f4"
As I commented, I guess the datatype of UID in your Firebird database is a CHAR(16) CHARACTER SET OCTETS, this is a binary datatype. Firebird (before Firebird 4) doesn't know the SQL types BINARY or VARBINARY, but fields with CHARACTER SET OCTETS are binary.
The value you are retrieving is probably a UUID. You either need to use the value as a binary, or select a human 'readable' UUID string using UUID_TO_CHAR:
SELECT FIRST 1 UUID_TO_CHAR(UID) FROM cmd