Help using Base SAS procedures

Facing problem while sorting.

Reply
Super Contributor
Posts: 276

Facing problem while sorting.

Hi all..

Iam having bellow code.

proc sort data=test;

by 'emp id'n 'emp target'n;

run;

data test1;

set test;

by 'emp id'n 'emp target'n;

if first.'emp id'n ne 1 then 'emp taget'n=0;

run;

if i run the code i am not getting the correct output.

i mean to say first. last. variables are not creating...

Some one saying it is because of variables...

please clarify me...

Frequent Contributor
Posts: 139

Facing problem while sorting.

Posted in reply to kuridisanjeev

First and last variables are hidden automatic variables. they will not be visible.If you want to view them assgin it to some difference variable.

proc sort data=test;

by 'emp id'n 'emp target'n;

run;

data test1;

set test;

by 'emp id'n 'emp target'n;

a=first.emp_id;

b=last.emp_id;

c=first.emp_target;

d-last.emp_target;

if first.'emp id'n ne 1 then 'emp taget'n=0;

run;

Super User
Posts: 10,018

Facing problem while sorting.

Posted in reply to kuridisanjeev

first. last. variables have already created by SAS.

But because they are temporary variables, they will not appear at PDV ,but at somewhere at memory.

And they will not output dataset defaultly.

Ksharp

Super Contributor
Posts: 276

Re: Facing problem while sorting.

Sorry to all.

A small typo error happened in my above post.

I am not getting correct output.

there i am using

if first.'emp id'n ne 1 then 'emp taget'n=0  condition.

this condition was not working because the variable names that i mentioned as 'emp id'n and 'emp taregt'n.

if I change variable names to emp_id and emp_target, the condition was working....

So  what's wrong with variable names?????

Frequent Contributor
Posts: 139

Re: Facing problem while sorting.

Posted in reply to kuridisanjeev

'n is used for what purpose?

Super Contributor
Posts: 276

Re: Facing problem while sorting.

Posted in reply to manojinpec

If you want to define  variable name with "space", generally we use n.

for example if you  want to create a variable with name "customer name",SAS won't accept this name directly because there is a space between customer and name..

For this you need to specify like this 'customer name'n.

Let me know if any clarification needed.

Thank you.

Sanjeev.

Frequent Contributor
Posts: 139

Re: Facing problem while sorting.

Posted in reply to kuridisanjeev

Is it applicable for SAS 8.2 . I am using sas 8.2 and i am not able to assign this name.

Super Contributor
Posts: 276

Facing problem while sorting.

Posted in reply to manojinpec

I don't think it works in 8.2.

this is the  new option which I found in SAS recently .

it is working in 9.2

Super User
Super User
Posts: 7,035

Re: Facing problem while sorting.

Posted in reply to manojinpec

You need to set validvarname=any.  But you are probably better off NOT using it.  You can use the variable label instead to store the description of the variable.  Most procs will list the label along with the variable name.  You can use the LABEL option for PROC PRINT to have the column headers be the label instead of the name.

1     data x;
2      'This name'n=100;
ERROR: The name This name is not a valid SAS name.
3    run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete.  When this step was stopped there were 0 observations and 0 variables.

4    options validvarname=any;
WARNING: Only the Base product and the SAS/STAT product have been tested for use with VALIDVARNAME=ANY. Other use of this option is considered
         experimental and may cause undetected errors.
5     data x;
6      'This name'n=100;
7    run;

NOTE: The data set WORK.X has 1 observations and 1 variables.
Ask a Question
Discussion stats
  • 8 replies
  • 322 views
  • 0 likes
  • 4 in conversation