Help using Base SAS procedures

questions about label in data set

Reply
N/A
Posts: 0

questions about label in data set

Hello
thank you cynthia for your answer at my last question.
I have now 2 new questions;
what is the equivalent code in proc sql for that :
imagine i have this dataset :

data tabinit;
format var1 $50.;
var1="G1*G2";
output;
var1="G3*G2*G1";
output;
var1="G2*G3";
output;
var1="youpi";
output;
var1="G1*G3";
output;
run;

and i do a data step :
data tabinit2;
set tabinit;
i=_n_;
run;

i am sure that i can do the last data step with proc sql but i cannot remenber the equivalent fonction of _n_ in proc sql for creating a new variable with the number of the rows inside.
thank you.

and my second question :
data tabinit3;
set tabinit;
miaou="azertugughu";
label var1=miaou; ****
run;


*** : the problem is that the label of var1 become "miaou" but i want that the label of var1 become what is written in the variable miaou : azertugughu !!!
is there a way to achieve this please ?
Thank you dear sas users
SAS Super FREQ
Posts: 8,739

Re: questions about label in data set

Hi:
I would just never attempt to duplicate what _N_ is doing in PROC SQL. If I were going to try to assign a number to every row that I create, I would do it in the first DATA step program:
[pre]
** 1) set macro variable for var1 label;
%let v1labl = azertugughu;

** 2) create data, increment counter and use macro variable;
data tabinit;
retain i 0;
label var1="&v1labl"
i = 'Number for Obs';
format var1 $50.;

var1="G1*G2";
i+1; /* increment i before output statement */
output;
var1="G3*G2*G1";
i+1;
output;
var1="G2*G3";
i+1;
output;
var1="youpi";
i+1;
output;
var1="G1*G3";
i+1;
output;
run;

** 3) use PROC PRINT;
proc print data=tabinit label;
run;
[/pre]

And the output from the PROC PRINT is:
[pre]
Number
Obs for Obs azertugughu

1 1 G1*G2
2 2 G3*G2*G1
3 3 G2*G3
4 4 youpi
5 5 G1*G3

[/pre]


cynthia
N/A
Posts: 0

Re: questions about label in data set

thank you for your answer but i try to find a way to create the label without a macro-variable like what i try to do in my last data-step. is it possible ?
in fact my aim is to work with the most special characters.
@+
N/A
Posts: 0

Re: questions about label in data set

Hi montpe,
It is possible only with macro ,if you want to include some special charecters in the label then include the value in %STR function.
Ask a Question
Discussion stats
  • 3 replies
  • 99 views
  • 0 likes
  • 2 in conversation