BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10

Hi 

Here I am trying to data manipulate using  do loop  

data dsn;
 do Sex= 1 to nobs ;
 length sex  $ 12 ;
 set sashelp.class nobs=nobs;
 if Sex='F' then Sex='Female';
 output;
 end;
 proc print;
 run;
6 REPLIES 6
Astounding
PROC Star
You first need to decide whether sex should be numeric or character. Even in these permissive times, it can't be both.
Tom
Super User Tom
Super User

I don't understand what the purpose of the DO loop is in that program.  If you want to recode the value used for females just do:

data WANT;
  length sex  $12 ;
  set sashelp.class ;
  if Sex='F' then Sex='Female';
run;

 

BrahmanandaRao
Lapis Lazuli | Level 10
I Know if condition so that I just trying do loops I took small dataset suppose if huge data then
Tom
Super User Tom
Super User

@BrahmanandaRao wrote:
I Know if condition so that I just trying do loops I took small dataset suppose if huge data then

The number of observations does not impact the code.

Cynthia_sas
Diamond | Level 26

Hi:

  If all you want to do is change the display of the variable for PROC PRINT, you can use a user-defined format for that. See #1 below. If you want to create a new character variable, then you can also do that with a user-defined format and the PUT function, no DO Loop or IF statement needed. See #2 example below.

Cynthia

Cynthia_sas_0-1625666854538.png

 

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1098 views
  • 0 likes
  • 5 in conversation