Help using Base SAS procedures

how to copy rows of a SAS data table on an iterative manner?

Reply
N/A
Posts: 0

how to copy rows of a SAS data table on an iterative manner?

Hi all,

I am a beginner on SAS and need your help.

I have a dataset consisting of 100 observations and 3 variables, where these three variables take a value of either 0 or 1 (they are binary). Suppose these three variables are v1, v2, and v3 respectively. I want to update my table considering the following conditions (where the column v4 has been created in advance):

For each single observation, I want to repeat the following action (beginning with the first one until the last observation):

Step1: Copy the row and paste it to the end of the table. If v1 is 0, assign 0 to v4 and jump to the next step. If v1 is 1, assign 1 to v4 and skip all the remaining steps (jump to the next observation).

Step2: Copy the row and paste it to the end of the table. If v2 is 0, assign 0 to v4 and jump to the next step. If v2 is 1, assign 1 to v4 and skip all the remaining steps (jump to the next observation).

Step3: Copy the row and paste it to the end of the table. If v3 is 0, assign 0 to v4 else assign 1 to v4. Jump to the next observation.

After the copy-paste operations, I also want to get rid off the first 100 rows (those rows which constitute the raw data).

I thank you in advance for your support. I hope that I did explain my problem explicitly.

Umut

Message was edited by: umutari Message was edited by: umutari
Super Contributor
Super Contributor
Posts: 3,174

Re: how to copy rows of a SAS data table on an iterative manner?

This task can be accomplished with DATA step programming in SAS. You have available to you (and it's free!) a vast amount of supplemental sample code, SAS-hosted DOC, and technical / conference topic material available to you at the SAS support http://support.sas.com/ website, in addition to the SAS discussion forum archives. Suggest you consider starting with the available SAS documentation, to build upon a SAS DATA step approach, adding IF / THEN ; logic, with INPUT statement to read up your file (if not already in SAS), and use OUTPUT statement logic as needed.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

data step programming introduction site:sas.com

step by step programming site:sas.com

sas programming examples site:sas.com
Occasional Contributor
Posts: 15

Re: how to copy rows of a SAS data table on an iterative manner?

Hi,

As far as I understood you question, the below code may be helpful..

data outputtablename;
set inputtablename;
if (v1=0 or v2=0 or v3=0) then v4=0;
if (v1=1 or v2=1 or v3=1) then v4=1;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 2148 views
  • 0 likes
  • 3 in conversation