recode values in a character variable based on another character variable's value in sasSAS - Reverse order of values of a Variable based on another Variable value in a TableReplacing some characters in a string with another characterWhat is the simplest way to recode a variable based on conditions of another variable in R?r recode a string variable based on a conditionRecode, categorical variables with massive amount of categories based on the mean of another variablerecode and add prefix to sas variablesHow to recode a variable into another variableapplying a loop to iteratively recode variables based on a macro variable (call symput/symget)Different Patterns of Recodes Based on Level of Another VariableRecode the value of a variable given the value of another oneRecode variable in R based on first characters of vector
Leaving a job that I just took based on false promise of a raise. What do I tell future interviewers?
Is it more effective to add yeast before or after kneading?
Hedging EURUSD with negative rates
When does removing Goblin Warchief affect its cost reduction ability?
CDG baggage claim before or after immigration?
Why is the missed-approach course for the "RNAV (GNSS) - A" approach to runway 28 at ENSB shaped all funny?
Do we know the situation in Britain before Sealion (summer 1940)?
What happens if nobody can form a government in Israel?
Social leper versus social leopard
Find missing number in the transformation
Resolving moral conflict
What are the benefits and disadvantages if a creature has multiple tails, e.g., Kyuubi or Nekomata?
Has my MacBook been hacked?
How does one calculate the distribution of the Matt Colville way of rolling stats?
How to manage expenditure when billing cycles and paycheck cycles are not aligned?
Allocating credit card points
What are these pixel-level discolored specks? How can I fix it?
Escape the labyrinth!
As a discovery writer, how do I complete an unfinished novel (which has highly diverged from the original plot ) after a time-gap?
Norwegian refuses EU delay (4.7 hours) compensation because it turned out there was nothing wrong with the aircraft
Is there any reason nowadays to use a neon indicator lamp instead of an LED?
What was an "insurance cover"?
Is it possible to encode a message in such a way that can only be read by someone or something capable of seeing into the very near future?
Where does an unaligned creature's soul go after death?
recode values in a character variable based on another character variable's value in sas
SAS - Reverse order of values of a Variable based on another Variable value in a TableReplacing some characters in a string with another characterWhat is the simplest way to recode a variable based on conditions of another variable in R?r recode a string variable based on a conditionRecode, categorical variables with massive amount of categories based on the mean of another variablerecode and add prefix to sas variablesHow to recode a variable into another variableapplying a loop to iteratively recode variables based on a macro variable (call symput/symget)Different Patterns of Recodes Based on Level of Another VariableRecode the value of a variable given the value of another oneRecode variable in R based on first characters of vector
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
jrnlfile is a dataset with journal names and identifiers. Here are the first 6 obs:
id journal issn
56201 ACTA HAEMATOLOGICA 0001-5792
94365 ACTA PHARMACOLOGICA SINICA
10334 ACTA PHARMACOLOGICA SINICA 1671-4083
55123 ADVANCES IN ENZYME REGULATION 0065-2571
90002 AGING
10403 AGING 1945-4589
Compare id 94365 and 10334. These obs name the same journal. They need the same issn. An obs with a missing value for issn almost always has at least one partner obs that contains a matching journal name and the correct issn. Wherever this is true, I want to recode the missing issn so it contains the issn seen in other instances where the same journal is mentioned. A revised dataset want would look like this:
id journal issn
56201 ACTA HAEMATOLOGICA 0001-5792
94365 ACTA PHARMACOLOGICA SINICA 1671-4083
10334 ACTA PHARMACOLOGICA SINICA 1671-4083
55123 ADVANCES IN ENZYME REGULATION 0065-2571
90002 AGING 1945-4589
10403 AGING 1945-4589
I currently use if-else statements in a data step to populate missing issn values with matching entries for journal:
data want;
set jrnlfile;
if journal = "ACTA PHARMACOLOGICA SINICA" then issn = "1671-4083";
else if journal = "AGING" then issn = "1945-4589";
/*continue for 7,000 other journals*/
run;
But jrnlfile contains 50,000 obs and 7,000 unique journals, so this takes a lot of time and is rather error-prone. This answer gets me halfway there, but issn is not numeric and I can't solve the problem by simply adding values to it.
What is a more efficient and systematic way to get to want from jrnlfile?
string sas recode
add a comment
|
jrnlfile is a dataset with journal names and identifiers. Here are the first 6 obs:
id journal issn
56201 ACTA HAEMATOLOGICA 0001-5792
94365 ACTA PHARMACOLOGICA SINICA
10334 ACTA PHARMACOLOGICA SINICA 1671-4083
55123 ADVANCES IN ENZYME REGULATION 0065-2571
90002 AGING
10403 AGING 1945-4589
Compare id 94365 and 10334. These obs name the same journal. They need the same issn. An obs with a missing value for issn almost always has at least one partner obs that contains a matching journal name and the correct issn. Wherever this is true, I want to recode the missing issn so it contains the issn seen in other instances where the same journal is mentioned. A revised dataset want would look like this:
id journal issn
56201 ACTA HAEMATOLOGICA 0001-5792
94365 ACTA PHARMACOLOGICA SINICA 1671-4083
10334 ACTA PHARMACOLOGICA SINICA 1671-4083
55123 ADVANCES IN ENZYME REGULATION 0065-2571
90002 AGING 1945-4589
10403 AGING 1945-4589
I currently use if-else statements in a data step to populate missing issn values with matching entries for journal:
data want;
set jrnlfile;
if journal = "ACTA PHARMACOLOGICA SINICA" then issn = "1671-4083";
else if journal = "AGING" then issn = "1945-4589";
/*continue for 7,000 other journals*/
run;
But jrnlfile contains 50,000 obs and 7,000 unique journals, so this takes a lot of time and is rather error-prone. This answer gets me halfway there, but issn is not numeric and I can't solve the problem by simply adding values to it.
What is a more efficient and systematic way to get to want from jrnlfile?
string sas recode
Can you sort the dataset by journal in a way that the value you want to use for ISSN is on the first observation for that journal?by journal descending issn;
– Tom
Mar 28 at 19:21
add a comment
|
jrnlfile is a dataset with journal names and identifiers. Here are the first 6 obs:
id journal issn
56201 ACTA HAEMATOLOGICA 0001-5792
94365 ACTA PHARMACOLOGICA SINICA
10334 ACTA PHARMACOLOGICA SINICA 1671-4083
55123 ADVANCES IN ENZYME REGULATION 0065-2571
90002 AGING
10403 AGING 1945-4589
Compare id 94365 and 10334. These obs name the same journal. They need the same issn. An obs with a missing value for issn almost always has at least one partner obs that contains a matching journal name and the correct issn. Wherever this is true, I want to recode the missing issn so it contains the issn seen in other instances where the same journal is mentioned. A revised dataset want would look like this:
id journal issn
56201 ACTA HAEMATOLOGICA 0001-5792
94365 ACTA PHARMACOLOGICA SINICA 1671-4083
10334 ACTA PHARMACOLOGICA SINICA 1671-4083
55123 ADVANCES IN ENZYME REGULATION 0065-2571
90002 AGING 1945-4589
10403 AGING 1945-4589
I currently use if-else statements in a data step to populate missing issn values with matching entries for journal:
data want;
set jrnlfile;
if journal = "ACTA PHARMACOLOGICA SINICA" then issn = "1671-4083";
else if journal = "AGING" then issn = "1945-4589";
/*continue for 7,000 other journals*/
run;
But jrnlfile contains 50,000 obs and 7,000 unique journals, so this takes a lot of time and is rather error-prone. This answer gets me halfway there, but issn is not numeric and I can't solve the problem by simply adding values to it.
What is a more efficient and systematic way to get to want from jrnlfile?
string sas recode
jrnlfile is a dataset with journal names and identifiers. Here are the first 6 obs:
id journal issn
56201 ACTA HAEMATOLOGICA 0001-5792
94365 ACTA PHARMACOLOGICA SINICA
10334 ACTA PHARMACOLOGICA SINICA 1671-4083
55123 ADVANCES IN ENZYME REGULATION 0065-2571
90002 AGING
10403 AGING 1945-4589
Compare id 94365 and 10334. These obs name the same journal. They need the same issn. An obs with a missing value for issn almost always has at least one partner obs that contains a matching journal name and the correct issn. Wherever this is true, I want to recode the missing issn so it contains the issn seen in other instances where the same journal is mentioned. A revised dataset want would look like this:
id journal issn
56201 ACTA HAEMATOLOGICA 0001-5792
94365 ACTA PHARMACOLOGICA SINICA 1671-4083
10334 ACTA PHARMACOLOGICA SINICA 1671-4083
55123 ADVANCES IN ENZYME REGULATION 0065-2571
90002 AGING 1945-4589
10403 AGING 1945-4589
I currently use if-else statements in a data step to populate missing issn values with matching entries for journal:
data want;
set jrnlfile;
if journal = "ACTA PHARMACOLOGICA SINICA" then issn = "1671-4083";
else if journal = "AGING" then issn = "1945-4589";
/*continue for 7,000 other journals*/
run;
But jrnlfile contains 50,000 obs and 7,000 unique journals, so this takes a lot of time and is rather error-prone. This answer gets me halfway there, but issn is not numeric and I can't solve the problem by simply adding values to it.
What is a more efficient and systematic way to get to want from jrnlfile?
string sas recode
string sas recode
asked Mar 28 at 15:39
JMQJMQ
4215 silver badges18 bronze badges
4215 silver badges18 bronze badges
Can you sort the dataset by journal in a way that the value you want to use for ISSN is on the first observation for that journal?by journal descending issn;
– Tom
Mar 28 at 19:21
add a comment
|
Can you sort the dataset by journal in a way that the value you want to use for ISSN is on the first observation for that journal?by journal descending issn;
– Tom
Mar 28 at 19:21
Can you sort the dataset by journal in a way that the value you want to use for ISSN is on the first observation for that journal?
by journal descending issn;– Tom
Mar 28 at 19:21
Can you sort the dataset by journal in a way that the value you want to use for ISSN is on the first observation for that journal?
by journal descending issn;– Tom
Mar 28 at 19:21
add a comment
|
2 Answers
2
active
oldest
votes
You can use retain statment. But there is restraints for this code. To empty journal will be set the first found issn. And there are must be a one or more issn for journal group.
proc sort data=JRNLFILE;
by journal descending issn;
run;
data want;
set JRNLFILE;
retain t_issn;
by journal descending issn;
if first.journal then
do;
if issn="" then do;
put "ERROR: there is no issn val for group";
stop;
end;
else t_issn =issn;
end;
if issn="" then
do;
issn=t_issn;
end;
run;
For example. If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 94365 | ACTA PHARMACOLOGICA SINICA | |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST |
| 2 | ACTA PHARMACOLOGICA SINICA | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED |
+-------+------------------------------+-----------+
You will get:
+-------+----------------------------+-----------+--------+
| id | journal | issn | t_issn |
+-------+----------------------------+-----------+--------+
| 2 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED | WAS |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST | WAS |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 | WAS |
| 94365 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
+-------+----------------------------+-----------+--------+
Error example.
If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 56201 | ACTA HAEMATOLOGICA | 0001-5792 |
| 94365 | ACTA PHARMACOLOGICA SINICA | |
+-------+------------------------------+-----------+
You will get an ERROR:
ERROR: there is no issn val for group
*t_issn leaved to understand function :))
add a comment
|
If the data is sorted by JOURNAL and the valid value appears first then a simple UPDATE might work. But watch out if there are other variables with missing values.
data want;
update have(obs=0) have ;
by journal;
output;
run;
You might try merging the data with the non-missing values of ISSN. That only requires that the data is sorted by JOURNAL. That will work very well if only one unique non-missing value is present. If there are multiple non-missing values then the results are not so nice.
data want ;
merge have have(where=(not missing(issn)) keep=journal issn rename=(issn=_2));
by journal;
if missing(issn) then issn=_2;
drop _2;
run;
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55401629%2frecode-values-in-a-character-variable-based-on-another-character-variables-valu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use retain statment. But there is restraints for this code. To empty journal will be set the first found issn. And there are must be a one or more issn for journal group.
proc sort data=JRNLFILE;
by journal descending issn;
run;
data want;
set JRNLFILE;
retain t_issn;
by journal descending issn;
if first.journal then
do;
if issn="" then do;
put "ERROR: there is no issn val for group";
stop;
end;
else t_issn =issn;
end;
if issn="" then
do;
issn=t_issn;
end;
run;
For example. If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 94365 | ACTA PHARMACOLOGICA SINICA | |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST |
| 2 | ACTA PHARMACOLOGICA SINICA | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED |
+-------+------------------------------+-----------+
You will get:
+-------+----------------------------+-----------+--------+
| id | journal | issn | t_issn |
+-------+----------------------------+-----------+--------+
| 2 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED | WAS |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST | WAS |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 | WAS |
| 94365 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
+-------+----------------------------+-----------+--------+
Error example.
If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 56201 | ACTA HAEMATOLOGICA | 0001-5792 |
| 94365 | ACTA PHARMACOLOGICA SINICA | |
+-------+------------------------------+-----------+
You will get an ERROR:
ERROR: there is no issn val for group
*t_issn leaved to understand function :))
add a comment
|
You can use retain statment. But there is restraints for this code. To empty journal will be set the first found issn. And there are must be a one or more issn for journal group.
proc sort data=JRNLFILE;
by journal descending issn;
run;
data want;
set JRNLFILE;
retain t_issn;
by journal descending issn;
if first.journal then
do;
if issn="" then do;
put "ERROR: there is no issn val for group";
stop;
end;
else t_issn =issn;
end;
if issn="" then
do;
issn=t_issn;
end;
run;
For example. If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 94365 | ACTA PHARMACOLOGICA SINICA | |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST |
| 2 | ACTA PHARMACOLOGICA SINICA | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED |
+-------+------------------------------+-----------+
You will get:
+-------+----------------------------+-----------+--------+
| id | journal | issn | t_issn |
+-------+----------------------------+-----------+--------+
| 2 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED | WAS |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST | WAS |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 | WAS |
| 94365 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
+-------+----------------------------+-----------+--------+
Error example.
If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 56201 | ACTA HAEMATOLOGICA | 0001-5792 |
| 94365 | ACTA PHARMACOLOGICA SINICA | |
+-------+------------------------------+-----------+
You will get an ERROR:
ERROR: there is no issn val for group
*t_issn leaved to understand function :))
add a comment
|
You can use retain statment. But there is restraints for this code. To empty journal will be set the first found issn. And there are must be a one or more issn for journal group.
proc sort data=JRNLFILE;
by journal descending issn;
run;
data want;
set JRNLFILE;
retain t_issn;
by journal descending issn;
if first.journal then
do;
if issn="" then do;
put "ERROR: there is no issn val for group";
stop;
end;
else t_issn =issn;
end;
if issn="" then
do;
issn=t_issn;
end;
run;
For example. If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 94365 | ACTA PHARMACOLOGICA SINICA | |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST |
| 2 | ACTA PHARMACOLOGICA SINICA | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED |
+-------+------------------------------+-----------+
You will get:
+-------+----------------------------+-----------+--------+
| id | journal | issn | t_issn |
+-------+----------------------------+-----------+--------+
| 2 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED | WAS |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST | WAS |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 | WAS |
| 94365 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
+-------+----------------------------+-----------+--------+
Error example.
If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 56201 | ACTA HAEMATOLOGICA | 0001-5792 |
| 94365 | ACTA PHARMACOLOGICA SINICA | |
+-------+------------------------------+-----------+
You will get an ERROR:
ERROR: there is no issn val for group
*t_issn leaved to understand function :))
You can use retain statment. But there is restraints for this code. To empty journal will be set the first found issn. And there are must be a one or more issn for journal group.
proc sort data=JRNLFILE;
by journal descending issn;
run;
data want;
set JRNLFILE;
retain t_issn;
by journal descending issn;
if first.journal then
do;
if issn="" then do;
put "ERROR: there is no issn val for group";
stop;
end;
else t_issn =issn;
end;
if issn="" then
do;
issn=t_issn;
end;
run;
For example. If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 94365 | ACTA PHARMACOLOGICA SINICA | |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST |
| 2 | ACTA PHARMACOLOGICA SINICA | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED |
+-------+------------------------------+-----------+
You will get:
+-------+----------------------------+-----------+--------+
| id | journal | issn | t_issn |
+-------+----------------------------+-----------+--------+
| 2 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
| 3 | ACTA PHARMACOLOGICA SINICA | SATRTED | WAS |
| 1 | ACTA PHARMACOLOGICA SINICA | A_TEST | WAS |
| 10334 | ACTA PHARMACOLOGICA SINICA | 1671-4083 | WAS |
| 94365 | ACTA PHARMACOLOGICA SINICA | WAS | WAS |
+-------+----------------------------+-----------+--------+
Error example.
If you use this table:
+-------+------------------------------+-----------+
| id | journal | issn |
+-------+------------------------------+-----------+
| 56201 | ACTA HAEMATOLOGICA | 0001-5792 |
| 94365 | ACTA PHARMACOLOGICA SINICA | |
+-------+------------------------------+-----------+
You will get an ERROR:
ERROR: there is no issn val for group
*t_issn leaved to understand function :))
edited Mar 28 at 16:07
answered Mar 28 at 15:57
Sanek ZhitnikSanek Zhitnik
7457 silver badges21 bronze badges
7457 silver badges21 bronze badges
add a comment
|
add a comment
|
If the data is sorted by JOURNAL and the valid value appears first then a simple UPDATE might work. But watch out if there are other variables with missing values.
data want;
update have(obs=0) have ;
by journal;
output;
run;
You might try merging the data with the non-missing values of ISSN. That only requires that the data is sorted by JOURNAL. That will work very well if only one unique non-missing value is present. If there are multiple non-missing values then the results are not so nice.
data want ;
merge have have(where=(not missing(issn)) keep=journal issn rename=(issn=_2));
by journal;
if missing(issn) then issn=_2;
drop _2;
run;
add a comment
|
If the data is sorted by JOURNAL and the valid value appears first then a simple UPDATE might work. But watch out if there are other variables with missing values.
data want;
update have(obs=0) have ;
by journal;
output;
run;
You might try merging the data with the non-missing values of ISSN. That only requires that the data is sorted by JOURNAL. That will work very well if only one unique non-missing value is present. If there are multiple non-missing values then the results are not so nice.
data want ;
merge have have(where=(not missing(issn)) keep=journal issn rename=(issn=_2));
by journal;
if missing(issn) then issn=_2;
drop _2;
run;
add a comment
|
If the data is sorted by JOURNAL and the valid value appears first then a simple UPDATE might work. But watch out if there are other variables with missing values.
data want;
update have(obs=0) have ;
by journal;
output;
run;
You might try merging the data with the non-missing values of ISSN. That only requires that the data is sorted by JOURNAL. That will work very well if only one unique non-missing value is present. If there are multiple non-missing values then the results are not so nice.
data want ;
merge have have(where=(not missing(issn)) keep=journal issn rename=(issn=_2));
by journal;
if missing(issn) then issn=_2;
drop _2;
run;
If the data is sorted by JOURNAL and the valid value appears first then a simple UPDATE might work. But watch out if there are other variables with missing values.
data want;
update have(obs=0) have ;
by journal;
output;
run;
You might try merging the data with the non-missing values of ISSN. That only requires that the data is sorted by JOURNAL. That will work very well if only one unique non-missing value is present. If there are multiple non-missing values then the results are not so nice.
data want ;
merge have have(where=(not missing(issn)) keep=journal issn rename=(issn=_2));
by journal;
if missing(issn) then issn=_2;
drop _2;
run;
answered Mar 28 at 22:48
TomTom
27.9k2 gold badges9 silver badges20 bronze badges
27.9k2 gold badges9 silver badges20 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55401629%2frecode-values-in-a-character-variable-based-on-another-character-variables-valu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you sort the dataset by journal in a way that the value you want to use for ISSN is on the first observation for that journal?
by journal descending issn;– Tom
Mar 28 at 19:21