BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
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
deleted_user
Not applicable
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.
@+
deleted_user
Not applicable
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.

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
  • 3 replies
  • 559 views
  • 0 likes
  • 2 in conversation