BookmarkSubscribeRSS Feed
yoyong
Obsidian | Level 7

Hi everyone.

 

I need help with recording.

 

I have two sets of variables.

 

First set contains the following:        LOC_P1__1,   LOC_P1__2,..  LOC_P1__N,    LOC_P2__1, LOC_P2__2, LOC_P2__N,...

Second set contains the following: TYPE_P1__1, TYPE_P1__2,..TYPE_P1__N, TYPE_P2__1,TYPE_P2__2, TYPE_P2__N,...

 

The options for 1st set are: a,b,c,d.

The options for 2nd set are: 1,2,3,4.

 

For each pair of variables (e.g. LOC_P1__1 and TYPE_P1__1, LOC_P1__N and TYPE_P1__N), I would like to recode where LOC_P1__1 = a and TYPE_P1__1 = 2; otherwise other possible combinations should be equal to missing.

 

How do I recode it without doing it multiple times?

 

Thank you.

 

2 REPLIES 2
Reeza
Super User

Recode from what to what? You didn’t explain that part. 

For the missing that’s trivial. Add an IF statement than checks your two variables and if they are not correct CALL MISSING sets the variables to missing. 

 

If ... then call missing (var1,var2, ...., varn);

 

Edit: You're probably looking at two array and a loop here. Not sure if you’re indicating just those two values with the set to missing or any N where a/2. Some sample input and output data would help. 

Array tutorial on recoding here 

https://stats.idre.ucla.edu/sas/seminars/sas-arrays/


@yoyong wrote:

Hi everyone.

 

I need help with recording.

 

I have two sets of variables.

 

First set contains the following:        LOC_P1__1,   LOC_P1__2,..  LOC_P1__N,    LOC_P2__1, LOC_P2__2, LOC_P2__N,...

Second set contains the following: TYPE_P1__1, TYPE_P1__2,..TYPE_P1__N, TYPE_P2__1,TYPE_P2__2, TYPE_P2__N,...

 

The options for 1st set are: a,b,c,d.

The options for 2nd set are: 1,2,3,4.

 

For each pair of variables (e.g. LOC_P1__1 and TYPE_P1__1, LOC_P1__N and TYPE_P1__N), I would like to recode where LOC_P1__1 = a and TYPE_P1__1 = 2; otherwise other possible combinations should be equal to missing.

 

How do I recode it without doing it multiple times?

 

Thank you.

 



 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Then show what the output should look like.  It is impossible for us to suggest something on things we cannot see.  From your text it looks like you have some variables for Last Observation Carried Forward (LOCF), could I ask why your not utilising CDISC standards on the format of your data, as these would then be identified as parameters?  That would be a very different structure to the one you describe.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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