<?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 Re: Why isn't this code converting my variable from numeric to character? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896845#M39900</link>
    <description>&lt;P&gt;We cannot tell why (or even whether) SAS is not making ZIPCD as character since you neither provided the PROC CONTENTS of the input dataset,&amp;nbsp;HypImpt.IowaResidents, nor the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If ZIPCD is not character then it is because ZIPCD already exists as a numeric variable in that dataset.&amp;nbsp; You cannot change the type of a variable once it has been defined already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens if you remove ZIPCD from the input dataset?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA  HypImpt.IowaResidents;
  SET  HypImpt.IowaResidents (drop=zipcd) ;
  ZipCd = PUT(NewZipCd, 2.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Oct 2023 03:39:56 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-10-03T03:39:56Z</dc:date>
    <item>
      <title>Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896843#M39898</link>
      <description>&lt;P&gt;I'm looking to convert ZipCd from a numeric variable to a character variable. The code below gives me no errors or warnings, but it is not converting the variable. What am I doing wrong? Is it related to the number within the PUT statement? (To be honest, I'm not totally sure what it does). Thanks for any help.&amp;nbsp;&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;PRE&gt;%LET CourseRoot = /home/u63571562/BIOS6680_2023;
LIBNAME HypImpt "&amp;amp;CourseRoot/Hypertension Study/Data/2_Import";
DATA	HypImpt.IowaResidents;
	SET	HypImpt.IowaResidents;

	ZipCd	= PUT(NewZipCd, 2.);

	RUN;

PROC PRINT DATA = HypImpt.IowaResidents;
	VAR ZipCd NewZipCd;
	RUN;&lt;/PRE&gt;&lt;/LI-SPOILER&gt;</description>
      <pubDate>Tue, 03 Oct 2023 03:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896843#M39898</guid>
      <dc:creator>BLT2023</dc:creator>
      <dc:date>2023-10-03T03:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896844#M39899</link>
      <description>&lt;P&gt;US zip codes are 5 digits long so your SAS format is too short - 2. should be 5.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 03:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896844#M39899</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-10-03T03:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896845#M39900</link>
      <description>&lt;P&gt;We cannot tell why (or even whether) SAS is not making ZIPCD as character since you neither provided the PROC CONTENTS of the input dataset,&amp;nbsp;HypImpt.IowaResidents, nor the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If ZIPCD is not character then it is because ZIPCD already exists as a numeric variable in that dataset.&amp;nbsp; You cannot change the type of a variable once it has been defined already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens if you remove ZIPCD from the input dataset?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA  HypImpt.IowaResidents;
  SET  HypImpt.IowaResidents (drop=zipcd) ;
  ZipCd = PUT(NewZipCd, 2.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Oct 2023 03:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896845#M39900</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-03T03:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896846#M39901</link>
      <description>&lt;P&gt;Thank you for the response, but this did not change the outcome.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 03:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896846#M39901</guid>
      <dc:creator>BLT2023</dc:creator>
      <dc:date>2023-10-03T03:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896847#M39902</link>
      <description>&lt;P&gt;Attached are the PROC CONTENTS (Variable 5 is what I am looking to have converted to character). Dropping ZipCd did not change anything. Here is the log:&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;PRE&gt; Errors
 Warnings
 Notes (5)
 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         DATAHypImpt.IowaResidents;
 70         SETHypImpt.IowaResidents (drop=ZipCd);
 71         
 72         ZipCd= PUT(NewZipCd, 5.);
 73         
 74         RUN;
 
 NOTE: There were 196 observations read from the data set HYPIMPT.IOWARESIDENTS.
 NOTE: The data set HYPIMPT.IOWARESIDENTS has 196 observations and 11 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.01 seconds
       user cpu time       0.01 seconds
       system cpu time     0.00 seconds
       memory              965.81k
       OS Memory           22184.00k
       Timestamp           10/03/2023 03:46:43 AM
       Step Count                        207  Switch Count  2
       Page Faults                       0
       Page Reclaims                     167
       Page Swaps                        0
       Voluntary Context Switches        44
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 
 75         
 76         PROC PRINT DATA = HypImpt.IowaResidents;
 77         VAR ZipCd NewZipCd;
 78         RUN;
 
 NOTE: There were 196 observations read from the data set HYPIMPT.IOWARESIDENTS.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.08 seconds
       user cpu time       0.08 seconds
       system cpu time     0.00 seconds
       memory              1158.62k
       OS Memory           22180.00k
       Timestamp           10/03/2023 03:46:43 AM
       Step Count                        208  Switch Count  0
       Page Faults                       0
       Page Reclaims                     74
       Page Swaps                        0
       Voluntary Context Switches        10
       Involuntary Context Switches      0
       Block Input Operations            288
       Block Output Operations           40
       
 
 79         
 79       !  PROC CONTENTS;
 80         
 81         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 91  &lt;/PRE&gt;&lt;/LI-SPOILER&gt;</description>
      <pubDate>Tue, 03 Oct 2023 03:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896847#M39902</guid>
      <dc:creator>BLT2023</dc:creator>
      <dc:date>2023-10-03T03:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896848#M39903</link>
      <description>&lt;P&gt;I can't tell from the information you've provided, which is your source variable and which is your target variable. You could have the variables swapped around in your PUT statement. The source variable must be inside the PUT function, and must be populated and numeric.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 03:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896848#M39903</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-10-03T03:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896849#M39904</link>
      <description>&lt;P&gt;ZipCd is my source variable. I am looking for a statement that converts the numeric values to character values in the new variable (which I name NewZipCd).&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 04:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896849#M39904</guid>
      <dc:creator>BLT2023</dc:creator>
      <dc:date>2023-10-03T04:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896856#M39905</link>
      <description>&lt;P&gt;Don't do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HypImpt.IowaResidents;
SET HypImpt.IowaResidents;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If something untoward happens in the step, you destroy the dataset you start with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Rerun the process you used for setting up your course data&lt;/U&gt;&lt;/STRONG&gt;, then run&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=hypImpt.iowaresidents (obs=10);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Given the fact that most of your variables are named varX (X being a number), and both newzipcd and zipcd appear at the physical end, I suspect that neither variable was part of the dataset to begin with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 06:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896856#M39905</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-10-03T06:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't this code converting my variable from numeric to character?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896868#M39906</link>
      <description>&lt;P&gt;The answer is hidden within the replies you have received.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you know, this statement fails to change the numeric ZipCd to the character NewZipCd.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ZipCd	= PUT(NewZipCd, 2.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The correct statement would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NewZipCd	= PUT(ZipCd, Z5.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The PUT function converts from numeric to character.&amp;nbsp; (Just for the record, it can also convert from character to character.)&amp;nbsp; The Z5 format requests 5 digits, with leading zeros as needed to flll out the five characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS statements that assign a value require the new variable name being created to appear before the equal sign, and the value to assign should appear to the right of the equal sign.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 08:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-isn-t-this-code-converting-my-variable-from-numeric-to/m-p/896868#M39906</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-10-03T08:32:09Z</dc:date>
    </item>
  </channel>
</rss>

