<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Creating new variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943113#M42361</link>
    <description>&lt;P&gt;Hi, here is my predicament. I'm taking a beginner SAS course concurrently with another course that relies on the information you learned in that beginner class. I have ZERO SAS experience, only R. One of the questions is like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Create a new variable called “abp” that is coded 1 if the individual’s daily alcohol consumption was 80 g per day or higher, and that is coded 0 if the individual’s daily alcohol consumption was less than 80 g per day."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the dataset, the acgp (original variable) is:&lt;/P&gt;&lt;P&gt;0 = 0-39 grams per day&lt;/P&gt;&lt;P&gt;1 = 40-79 grams per day&lt;/P&gt;&lt;P&gt;2 = 80-119 grams per day&lt;/P&gt;&lt;P&gt;3 = 120+ grams per day&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, just by scouring around youtube and other resources, I did:&amp;nbsp;&lt;/P&gt;&lt;P&gt;if acgp in (2,3) THEN abp = 1;&lt;BR /&gt;ELSE IF acgp in (0,1) THEN abp = 0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now this will run but the output data is nothing, it gives me two columns with acgp and acp and no rows. The code I received was from a few basic codes given to me. I don't know SAS at all, so I don't know if I have to do anything else before doing the IF/ELSE statement? My data is a SAS data set, its already read into my program. Any advice would be VERY much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Sep 2024 10:11:21 GMT</pubDate>
    <dc:creator>StudyBeane</dc:creator>
    <dc:date>2024-09-09T10:11:21Z</dc:date>
    <item>
      <title>Creating new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943113#M42361</link>
      <description>&lt;P&gt;Hi, here is my predicament. I'm taking a beginner SAS course concurrently with another course that relies on the information you learned in that beginner class. I have ZERO SAS experience, only R. One of the questions is like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Create a new variable called “abp” that is coded 1 if the individual’s daily alcohol consumption was 80 g per day or higher, and that is coded 0 if the individual’s daily alcohol consumption was less than 80 g per day."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the dataset, the acgp (original variable) is:&lt;/P&gt;&lt;P&gt;0 = 0-39 grams per day&lt;/P&gt;&lt;P&gt;1 = 40-79 grams per day&lt;/P&gt;&lt;P&gt;2 = 80-119 grams per day&lt;/P&gt;&lt;P&gt;3 = 120+ grams per day&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, just by scouring around youtube and other resources, I did:&amp;nbsp;&lt;/P&gt;&lt;P&gt;if acgp in (2,3) THEN abp = 1;&lt;BR /&gt;ELSE IF acgp in (0,1) THEN abp = 0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now this will run but the output data is nothing, it gives me two columns with acgp and acp and no rows. The code I received was from a few basic codes given to me. I don't know SAS at all, so I don't know if I have to do anything else before doing the IF/ELSE statement? My data is a SAS data set, its already read into my program. Any advice would be VERY much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 10:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943113#M42361</guid>
      <dc:creator>StudyBeane</dc:creator>
      <dc:date>2024-09-09T10:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943114#M42362</link>
      <description>&lt;P&gt;Show us the entire data step code, not a few selected lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us the log from running this data step (we need to see the code from this data step &lt;EM&gt;as it appears in the log&lt;/EM&gt;, and any ERRORs/WARNINGs/NOTEs that appear in the log)&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 11:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943114#M42362</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-09T11:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943120#M42363</link>
      <description>&lt;P&gt;If you did not use a SET statement to read the existing dataset, you only get these two variables with missing values in a single observation.&lt;/P&gt;
&lt;P&gt;Please share the complete code of the step (from the DATA to the RUN statement).&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 11:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943120#M42363</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-09-09T11:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943122#M42364</link>
      <description>&lt;P&gt;You left out two key pieces of information needed to create a program to do what you wanted.&lt;/P&gt;
&lt;P&gt;The NAME of the existing dataset that has the variable ACGP.&lt;/P&gt;
&lt;P&gt;The NAME of the NEW dataset you want to create that will have the NEW variable ABP.&lt;/P&gt;
&lt;P&gt;Let's assume those are HAVE and WANT, respectively.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your logic does not have any instructions for what to do when the value ACGP is something else, such as a missing value or an invalid code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if acgp in (2,3) then abp = 1;
  else if acgp in (0,1) then abp = 0;
  else abp=.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are willing to have missing or invalid codes mapped to 0 then you can simplify the logic to just assigning the result of the first boolean test to ABP.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  abp = (acgp in (2,3));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will work because SAS evaluate boolean expressions to either 1 (TRUE) or 0 (FALSE).&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 12:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943122#M42364</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-09T12:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943144#M42367</link>
      <description>&lt;P&gt;Yes, thank you, I am extremely new to SAS and didn't realize I had to use use data/set.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 13:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943144#M42367</guid>
      <dc:creator>StudyBeane</dc:creator>
      <dc:date>2024-09-09T13:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943166#M42372</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/469337"&gt;@StudyBeane&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, thank you, I am extremely new to SAS and didn't realize I had to use use data/set.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In R don't you have to provide some data source before creating a new variable based on existing values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pretty much the case in any of the 20+ "programming languages" I have used over the years. No input data = no meaningful output data. The principles wont change but approach will change based on the language used.&amp;nbsp; Such&amp;nbsp; as how to point to the existing data: Set statement for a SAS data set or DATA= for almost every other SAS procedure, and where to put the output: Data statement with the Data step code. Other approaches in&amp;nbsp; other procedures but OUTPUT or OUT= are fairly common but the syntax can vary based on the procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will default to the last created data set as input for many procedures but the Data step still needs a SET statement to do such even if no data set name is provided.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 15:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-new-variable/m-p/943166#M42372</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-09-09T15:04:40Z</dc:date>
    </item>
  </channel>
</rss>

