I would like to know how to put a single quote around a ssis vaiable, say I have a Variable name Variable, but the value is MyTable
#[User::Variable]
output =
MyTable
However, I want the output to look like this
'MyTable'
So how would the syntax look like on SSIS to accomplish this please?
Found out by chance, not a fan of SSIS expression Syntax at all!!!
"'"+#[User::TableName]+"'"
Related
So I want to read a text file with the following format:
Bob, G92f22f, Fggggfdff32
Rob, f3h9123, fdsgfdsg3
Sally, f2g4g, g3g3hgdsd
I want a simple Lua program that can filter out say "bob" and then say throw the data into a variable to use in a program.
a = Bob
b = G92f22f
c = Fggggfdff32
I assume then I could do
print(a,b,c)
Still quite new to Lua having a heck of a time with anything read / variable though.
You'll want to look at the io and string modules; they handle things like reading from / writing to files and doing pattern matching on strings.
Luas pattern matching is a bit simple compared to the regular expressions most modern languages use, but from what I see in your example, you could probably match a "word" as [^, ]+, that is, one or more characters that aren't a comma or a space
I should check existence of values based on some conditions.
i.e. i have 3 variables, varA, varB and varC. varC should not be empty only if varA>varB (condition).
i normally use some syntax to check any of the variables and run a frequency of any of them to see if there are errors:
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
exe.
fre ck_varC.
exe.
I had some errors when the condition became complex and when in the condition there are missing() or other functions but i could have made a mistake.
do you think there is an easier way of doing this checks?
thanks in advance
EDIT: here an example of what i mean, think at a questionnaire with some routing, you ask age to anyone, if they are between 17 and 44 ask them if they work, if they work ask them how many hours.
i have an excel tool where i put down all variables with all conditions, then it will generate the syntax in the example, all with the same structure for all variables, considering both situations, we have a value that shouldn't be there or we don't have a value that should be there.
is there an easier way of doing that? is this structure always valid no matter what is the condition?
In SPSS, missing values are not numbers. You need to explicitly program those scenarios as well. you got varC covered (partially), but no scenario where varA or varB have missing data is covered.
(As good practice, maybe you should initialize your check variable as sysmis or 0, using syntax):
numeric ck_varC (f1.0).
compute ck_varC=0.
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
***additional conditional scenarios go here:.
if missing(varA) or missing(varB) ck_varC=3.
...
fre ck_varC.
By the way - you do not need any of the exe. commands if you are going to run your syntax as a whole.
Later Edit, after the poster updated the question:
Your syntax would be something like this. Note the use of the range function, which is not mandatory, but might be useful for you in the future.
I am also assuming that work is a string variable, so its values need to be referenced using quotation signs.
if missing(age) ck_age=1.
if missing(work) and range(age,17,44) ck_work=1.
if missing(hours) and work="yes" ck_hours=1.
if not (missing (age)) and not(1>0) ck_age=2. /*this will never happen because of the not(1>0).
if not(missing(work)) and (not range(age,17,44)) ck_work=2. /*note that if age is missing, this ck_work won't be set here.
if not(missing(hours)) and (not(work="yes")) ck_hours=2.
EXECUTE.
String variables are case sensitive
There is no missing equivalent in strings; an empty blank string ("") is still a string. not(work="yes") is True when work is blank ("").
I'm currently learning SAS and I got a code to be adapted and reused but first I have to understand it. My question is about just a small part of it (top of the code). Here it is:
%let dir=/home/user/PROJECT/CODES/;
%let dir_project=/home/user/PROJECT/;
libname inp "&dir_project" compress=yes;
libname out "&dir.out" compress=yes;
%let tg=out.vip;
My questions are:
What does &dir.out mean? What is it referring to? I suppose it's something called "out". Is it looking for a database OUT? If yes and all my databases are usually temporary ones in WORK should I change it to WORK.OUT?
What is the resulting path of "tg"? I doubt that it is: "/home/user/PROJECT/CODES/out.vip".
Originally the code was referring to some locations on C: drive but I work entirely in SAS Studio so I have to adapt it.
Thank you in advance
The first two statements define two macro variables, DIR and DIR_PROJECT. In the second two statements you use those macro variables to define two librefs, INP and OUT. The last statement just defines another macro variable named TG.
Macro variable references start with & and are followed by the name of the macro variable to expand. SAS will stop looking for the macro variable name when is sees a character that cannot be part of a macro variable name or a period. That is why the first libname statement uses the value of the DIR_PROJECT macro variable instead of the DIR macro variable. The period in the second libname statement tells SAS that you want to replace &dir. with the value of the macro variable DIR. If you had instead just written &dirout then SAS would look for a macro variable named DIROUT.
Macro variable just contain text. The meaning of the text depends on what SAS code you generate with them. So the first two macro variable look like they contain absolute paths to directories on your Unix file system, since they start from the root node / and end with a /. This is confirmed by how you use them to generate libname statements.
By adding the constant text out after the path in the second libname statement the result is that you are looking for a sub-directory named out in the directory that the value of the macro variable DIR names.
As for the last macro variable TG what it means depends on how it is used. Since it is of the form of two names separated by a period then it looks like it can be used to refer to a SAS dataset. Especially since the first name is the same as one of the librefs that you defined in the libname statements. So you might use that macro variable in code like this:
proc print data=&tg ; run;
Which would be expanded into:
proc print data=out.vip ; run;
In that case you are looking for the SAS dataset named VIP in the library named OUT. So you would be looking for the Unix file named:
/home/user/PROJECT/CODES/out/vip.sas7bdat
Now if you used that macro variable in some SQL code like this:
select &tg ...
Then it would expand to
select out.vip ....
and in that case you would be referencing a variable named VIP in an input dataset named (or aliased as) OUT.
1 - &dir. is a macro variable. The period marks the end of the variable, and thus &dir.out resolves to /home/user/PROJECT/CODES/out at runtime. Your libname statement will now link the libref out to this physical location.
2 - the tg variable is a dataset reference, in the form "library.dataset". Here, out is the library, and vip is the dataset. This way you can write code such as:
data &tg.;
set sashelp.class;
run;
To create the dataset vip in the out library.
In this way, you are in fact (almost) right. The resulting path of &tg. (which resolves to out.vip) will be /home/user/PROJECT/CODES/out/vip.sas7bdat.
I am not used to SPSS so this question will sound stupid:
I need to change fragments of a cell in spss, exemple:
'1.28'
'2.69'
'3.57'
to
'a.28'
'b.69'
'c.57'
What's the best way to do it?
Tks.
This is assuming the variable you want to recode is called 'VarA', and that it is numeric.
This creates a copy of the variable, converts it to a string, and then uses those values to create a new version that is recoded.
RECODE VarA (ELSE = COPY) INTO VarA_String.
ALTER TYPE VarA_String(A8).
EXECUTE.
COMPUTE VarA_r=REPLACE(VarA_String,'1.','a.').
COMPUTE VarA_r=REPLACE(VarA_String,'2.','b.').
COMPUTE VarA_r=REPLACE(VarA_String,'3.','c.').
EXECUTE.
The syntax is a little different in SPSS Modeler and bear with me as I can only attach one image until I have a certain reputation on SO.
After you convert VarA into a string (which I called to_str) you can use the replace command to change part of the substring, ie:
to_string(VarA)
for the first Derive node, and:
replace('1.','a.',to_str)
for the second Derive node, this command replaces all occurrences of SUBSTRING1 with SUBSTRING2 in STRING and you will get the same result but in Modeler, see the sample stream here
Assuming that these are strings, see the replace function in COMPUTE. If there are just a few, though, just edit the cells in the Data Editor.
I wanted to inserted a variable in the middle of my data file through syntax, But could not find the way to do this, do anybody know this how to do?
Regards,
Ramamoorthy.
MATCH FILES FILE=* /KEEP=var1 var2 var3 .
execute.
Using this syntax you can order the variables in the way you want.