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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 573 views
  • 0 likes
  • 2 in conversation