Hello:
Could someone please explain what Q: is?
what is ne . ?
thanks
Much appreciated
data transposed;set base;
array Qtr{3} Q:;
do i = 1 to 3;Period = cat('Qtr',i);Amount = Qtr{i} ;output;end;
drop Q1:Q3;
if Amount ne .;
run;
Could someone please explain what Q: is?
In general colon ( : ) is used to separate the lower and upper bounds of an array’s dimension.
but in your example it has another purpose which is dealing with unknown numbers of variables after the transposing.
By default, PROC TRANSPOSE names these variables Col1, Col2, Col3...up to the maximum.
So you can process the various Col# variables using an ARRAY statement like array Qtr{3} col:;
but it seam that in the PROC TRANSPOSE he added prefix=Q, so he changed col: to Q:
So it is not general syntax, but specific use.
what is ne . ?
NE is Mnemonic Equivalent to the symbol ^=
ne . mean if not equal to null, mean if not missing for example.
Thank you
I just started using SAS and was learning about it. I probably will be asking lots of basic questions.
Thank you
I just started using SAS and was learning about it. I probably will be asking lots of basic questions.
Q: is a shorthand notation to include all variables that start with Q, in this case Q1, Q2, Q3
Ne => Not Equal
. => missing
Not equal to missing
Thanks guys
Then what about this..
proc transpose data = base out = transposed
(rename=(Col1=Amount) where=(Amount ne .)) name=Period;
shouldn't col2 be amount?? (In the transposed table Col1 is period and col2 is amount) and what is name = Period in this?
Message was edited by: Abhinav Shori
It's hard to know what COL1 and COL2 since you didn't post BASE or the rest of the PROC TRANSPOSE statements.
NAME=PERIOD changes the name of the name variable (_NAME_) to PERIOD. There is also a similar option, LABEL=, to change the name of the label variable (_LABEL_)
thanks and this is the table
You need to supply some example data, in datastep form, for others to understand what you are doing and asking.
Regardless, I'm responding to your initial post. Q1:Q3 is an error that I'm surprised SAS ignores. I presume the coder meant to use Q1-Q3 to drop Q1, Q2, and Q3. However, as written, it will drop any variable that start with Q1, as well as the variable Q3.
Arthur Tabachneck wrote:
. Q1:Q3 is an error that I'm surprised SAS ignores.
Why do you think that is or should be an error? As you state it drops all variables that start with Q1 and the variable Q3. I don't think SAS considers the fact only one variable Q1 starts with Q1. The only thing that looks odd to us perhaps is that there is no space between : and Q3, but non is needed.
DN: I stand corrected! Q1:Q3 is definitely not an error. However, given that the same syntax would represent a range in Excel, I have to wonder how often it has been incorrectly used in SAS code.
Your code produces:
Period Amount Col2
q1 | 3 | 32 |
q2 | 134 | 23 |
q3 | 12 | 24 |
Is the table you showed, labeled transpose, what you were expecting?
@Arthur Tabachneck
the solution you wrote was what I had expected but the solution I got is shown in table (transposed, above).
Thanks
You must also have BY CUST;.
You need to show your code, always show the code.
proc transpose data = base out = transposed
(rename=(Col1=Amount) where=(Amount ne .)) name=Period;
by cust; run;
complete code
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.