BookmarkSubscribeRSS Feed
Luffy
Calcite | Level 5

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; 
17 REPLIES 17
mohamed_zaki
Barite | Level 11

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.

Luffy
Calcite | Level 5

Thank you Smiley Happy

I just started using SAS and was learning about it. I probably will be asking lots of basic questions.

Luffy
Calcite | Level 5

Thank you Smiley Happy

I just started using SAS and was learning about it. I probably will be asking lots of basic questions.

Reeza
Super User

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

Luffy
Calcite | Level 5

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

data_null__
Jade | Level 19

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_)

Luffy
Calcite | Level 5

thanks Smiley Happy and this is the table

art297
Opal | Level 21

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.

data_null__
Jade | Level 19

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.

art297
Opal | Level 21

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.

art297
Opal | Level 21

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?

Luffy
Calcite | Level 5

@Arthur Tabachneck

the solution you wrote was what I had expected but the solution I got is shown in table (transposed, above).

Thanks

data_null__
Jade | Level 19

You must also have BY CUST;.

You need to show your code, always show the code.

Luffy
Calcite | Level 5

proc transpose data = base out = transposed

  (rename=(Col1=Amount) where=(Amount ne .)) name=Period;

by cust; run;

complete code

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 1460 views
  • 1 like
  • 5 in conversation